Skip to content

Commit 6161373

Browse files
committed
Merge branch 'master' into cleanup-main-module
2 parents c1ded82 + 8067d4f commit 6161373

27 files changed

+125
-154
lines changed

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package ghcide
2424

2525
write-ghc-environment-files: never
2626

27-
index-state: 2021-02-15T19:11:03Z
27+
index-state: 2021-02-15T19:02:22Z
2828

2929
allow-newer:
3030
active:base,

exe/Wrapper.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
module Main where
55

66
import Control.Monad.Extra
7+
import Data.Default
78
import Data.Foldable
89
import Data.List
910
import Data.Void
10-
import Development.IDE.Session (findCradle, defaultLoadingOptions)
11+
import Development.IDE.Session (findCradle)
1112
import HIE.Bios hiding (findCradle)
1213
import HIE.Bios.Environment
1314
import HIE.Bios.Types
@@ -140,7 +141,7 @@ getRuntimeGhcVersion' cradle = do
140141
-- of the project that may or may not be accurate.
141142
findLocalCradle :: FilePath -> IO (Cradle Void)
142143
findLocalCradle fp = do
143-
cradleConf <- findCradle defaultLoadingOptions fp
144+
cradleConf <- findCradle def fp
144145
crdl <- case cradleConf of
145146
Just yaml -> do
146147
hPutStrLn stderr $ "Found \"" ++ yaml ++ "\" for \"" ++ fp ++ "\""

ghcide/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
### 0.7.5 (2021-02-??)
2+
* Tone down some logInfos to logDebug (#1385) - Pepe Iborra
3+
* Show window message when auto extending import lists (#1371) - Potato Hatsue
4+
* Catch GHC errors in listing module names (#1367) - Potato Hatsue
5+
* Upgrade to lsp-1.0 (#1284) - wz1000
26
* Added Development.IDE.Main (#1338) - Pepe Iborra
7+
* Fix completion snippets on DuplicateRecordFields (#1360) - Potato Hatsue
8+
* Add code action for hiding shadowed identifiers from imports (#1322) - Potato Hatsue
9+
* Make find-definition work better with multi-components (#1357) - wz1000
10+
* Index files on first open (#1358) - wz1000
11+
* Fix code actions regression (#1349) - Pepe Iborra
312

413
### 0.7.4 (2021-02-08)
514
* Support for references via hiedb (#704) - wz1000

ghcide/bench/config.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ examples:
2424
- src/Language/LSP/VFS.hs
2525
- src/Language/LSP/Types/Lens.hs
2626
# Small but heavily multi-component example
27-
- path: bench/example/HLS
28-
modules:
29-
- hls-plugin-api/src/Ide/Plugin/Config.hs
30-
- ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs
31-
# Things get too slow with more than 2 components, hie-bios 0.7.3 will help here
32-
# - ghcide/bench/hist/Main.hs
33-
# - ghcide/bench/lib/Experiments/Types.hs
34-
# - ghcide/test/exe/Main.hs
35-
# - exe/Plugins.hs
27+
# Disabled as it is far to slow. hie-bios >0.7.2 should help
28+
# - path: bench/example/HLS
29+
# modules:
30+
# - hls-plugin-api/src/Ide/Plugin/Config.hs
31+
# - ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs
32+
# - ghcide/bench/hist/Main.hs
33+
# - ghcide/bench/lib/Experiments/Types.hs
34+
# - ghcide/test/exe/Main.hs
35+
# - exe/Plugins.hs
3636

3737
# The set of experiments to execute
3838
experiments:

ghcide/exe/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ main = do
6666
DbCmd opts cmd -> do
6767
dir <- IO.getCurrentDirectory
6868
dbLoc <- getHieDbLoc dir
69-
mlibdir <- setInitialDynFlags
69+
mlibdir <- setInitialDynFlags def
7070
case mlibdir of
7171
Nothing -> exitWith $ ExitFailure 1
7272
Just libdir -> runCommand libdir opts{database = dbLoc} cmd
@@ -79,7 +79,7 @@ main = do
7979
hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
8080
_ -> return ()
8181

82-
Main.defaultMain Main.defArguments
82+
Main.defaultMain def
8383
{Main.argFiles = case argFilesOrCmd of
8484
Typecheck x | not argLSP -> Just x
8585
_ -> Nothing

ghcide/ghcide.cabal

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ source-repository head
2727
type: git
2828
location: https://github.com/haskell/ghcide.git
2929

30-
flag ghc-lib
31-
description: build against ghc-lib instead of the ghc package
32-
default: False
33-
manual: True
34-
3530
library
3631
default-language: Haskell2010
3732
build-depends:
@@ -62,7 +57,7 @@ library
6257
lens,
6358
hiedb == 0.3.0.1,
6459
lsp-types == 1.1.*,
65-
lsp == 1.1.*,
60+
lsp == 1.1.1.0,
6661
mtl,
6762
network-uri,
6863
parallel,
@@ -92,19 +87,10 @@ library
9287
opentelemetry >=0.6.1,
9388
heapsize ==0.3.*,
9489
unliftio,
95-
unliftio-core
96-
if flag(ghc-lib)
97-
build-depends:
98-
ghc-lib >= 8.8,
99-
ghc-lib-parser >= 8.8
100-
cpp-options: -DGHC_LIB
101-
else
102-
build-depends:
90+
unliftio-core,
10391
ghc-boot-th,
10492
ghc-boot,
10593
ghc >= 8.6,
106-
-- These dependencies are used by Development.IDE.Session and are
107-
-- Haskell specific. So don't use them when building with -fghc-lib!
10894
ghc-check >=0.5.0.1,
10995
ghc-paths,
11096
cryptohash-sha1 >=0.11.100 && <0.12,
@@ -141,6 +127,7 @@ library
141127

142128
hs-source-dirs:
143129
src
130+
session-loader
144131
include-dirs:
145132
include
146133
exposed-modules:
@@ -169,6 +156,7 @@ library
169156
Development.IDE.LSP.LanguageServer
170157
Development.IDE.LSP.Outline
171158
Development.IDE.LSP.Server
159+
Development.IDE.Session
172160
Development.IDE.Spans.Common
173161
Development.IDE.Spans.Documentation
174162
Development.IDE.Spans.AtPoint
@@ -191,26 +179,14 @@ library
191179
Development.IDE.Plugin.Test
192180
Development.IDE.Plugin.TypeLenses
193181

194-
-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
195-
-- the real GHC library and the types are incompatible. Furthermore, when
196-
-- building with ghc-lib we need to make this Haskell agnostic, so no
197-
-- hie-bios!
198-
-- We also put these modules into a separate hs-source-dirs so we can avoid
199-
-- compiling them at all if ghc-lib is not set
200-
if !flag(ghc-lib)
201-
hs-source-dirs:
202-
session-loader
203-
exposed-modules:
204-
Development.IDE.Session
205-
other-modules:
206-
Development.IDE.Session.VersionCheck
207182
other-modules:
208183
Development.IDE.Core.FileExists
209184
Development.IDE.GHC.CPP
210185
Development.IDE.GHC.Warnings
211186
Development.IDE.LSP.Notifications
212187
Development.IDE.Plugin.CodeAction.PositionIndexed
213188
Development.IDE.Plugin.Completions.Logic
189+
Development.IDE.Session.VersionCheck
214190
Development.IDE.Types.Action
215191
ghc-options: -Wall -Wno-name-shadowing -Wincomplete-uni-patterns -Wno-unticked-promoted-constructors
216192

@@ -261,8 +237,6 @@ benchmark benchHist
261237
yaml
262238

263239
executable ghcide
264-
if flag(ghc-lib)
265-
buildable: False
266240
default-language: Haskell2010
267241
include-dirs:
268242
include
@@ -322,8 +296,6 @@ executable ghcide
322296
ViewPatterns
323297

324298
test-suite ghcide-tests
325-
if flag(ghc-lib)
326-
buildable: False
327299
type: exitcode-stdio-1.0
328300
default-language: Haskell2010
329301
build-tool-depends:

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The logic for setting up a ghcide session by tapping into hie-bios.
88
module Development.IDE.Session
99
(SessionLoadingOptions(..)
1010
,CacheDirs(..)
11-
,defaultLoadingOptions
1211
,loadSession
1312
,loadSessionWithOptions
1413
,setInitialDynFlags
@@ -34,6 +33,7 @@ import qualified Data.Text as T
3433
import Data.Aeson
3534
import Data.Bifunctor
3635
import qualified Data.ByteString.Base16 as B16
36+
import Data.Default
3737
import Data.Either.Extra
3838
import Data.Function
3939
import Data.Hashable
@@ -98,31 +98,38 @@ data SessionLoadingOptions = SessionLoadingOptions
9898
-- return the path for storing generated GHC artifacts,
9999
-- or 'Nothing' to respect the cradle setting
100100
, getCacheDirs :: String -> [String] -> IO CacheDirs
101+
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
102+
, getInitialGhcLibDir :: IO (Maybe LibDir)
101103
}
102104

103-
defaultLoadingOptions :: SessionLoadingOptions
104-
defaultLoadingOptions = SessionLoadingOptions
105-
{findCradle = HieBios.findCradle
106-
,loadCradle = HieBios.loadCradle
107-
,getCacheDirs = getCacheDirsDefault
108-
}
105+
instance Default SessionLoadingOptions where
106+
def = SessionLoadingOptions
107+
{findCradle = HieBios.findCradle
108+
,loadCradle = HieBios.loadCradle
109+
,getCacheDirs = getCacheDirsDefault
110+
,getInitialGhcLibDir = getInitialGhcLibDirDefault
111+
}
109112

110-
-- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
111-
setInitialDynFlags :: IO (Maybe LibDir)
112-
setInitialDynFlags = do
113+
getInitialGhcLibDirDefault :: IO (Maybe LibDir)
114+
getInitialGhcLibDirDefault = do
113115
dir <- IO.getCurrentDirectory
114116
hieYaml <- runMaybeT $ yamlConfig dir
115117
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios.loadCradle hieYaml
116118
hPutStrLn stderr $ "setInitialDynFlags cradle: " ++ show cradle
117119
libDirRes <- getRuntimeGhcLibDir cradle
118-
libdir <- case libDirRes of
120+
case libDirRes of
119121
CradleSuccess libdir -> pure $ Just $ LibDir libdir
120122
CradleFail err -> do
121123
hPutStrLn stderr $ "Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
122124
pure Nothing
123125
CradleNone -> do
124126
hPutStrLn stderr $ "Couldn't load cradle (CradleNone)"
125127
pure Nothing
128+
129+
-- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
130+
setInitialDynFlags :: SessionLoadingOptions -> IO (Maybe LibDir)
131+
setInitialDynFlags SessionLoadingOptions{..} = do
132+
libdir <- getInitialGhcLibDir
126133
dynFlags <- mapM dynFlagsForPrinting libdir
127134
mapM_ setUnsafeGlobalDynFlags dynFlags
128135
pure libdir
@@ -177,7 +184,7 @@ getHieDbLoc dir = do
177184
-- components mapping to the same hie.yaml file are mapped to the same
178185
-- HscEnv which is updated as new components are discovered.
179186
loadSession :: FilePath -> IO (Action IdeGhcSession)
180-
loadSession = loadSessionWithOptions defaultLoadingOptions
187+
loadSession = loadSessionWithOptions def
181188

182189
loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession)
183190
loadSessionWithOptions SessionLoadingOptions{..} dir = do
@@ -614,7 +621,7 @@ should be filtered out, such that we dont have to re-compile everything.
614621
-- For the exact reason, see Note [Avoiding bad interface files].
615622
setCacheDirs :: MonadIO m => Logger -> CacheDirs -> DynFlags -> m DynFlags
616623
setCacheDirs logger CacheDirs{..} dflags = do
617-
liftIO $ logInfo logger $ "Using interface files cache dir: " <> T.pack cacheDir
624+
liftIO $ logInfo logger $ "Using interface files cache dir: " <> T.pack (fromMaybe cacheDir hiCacheDir)
618625
pure $ dflags
619626
& maybe id setHiDir hiCacheDir
620627
& maybe id setHieDir hieCacheDir

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ module Development.IDE.Core.Rules(
5757
getBindingsRule,
5858
needsCompilationRule,
5959
generateCoreRule,
60-
getImportMapRule
60+
getImportMapRule,
61+
regenerateHiFile,
62+
ghcSessionDepsDefinition,
63+
getParsedModuleDefinition,
64+
typeCheckRuleDefinition,
6165
) where
6266

6367
import Fingerprint
@@ -633,17 +637,7 @@ getDocMapRule =
633637
(hscEnv -> hsc, _) <- useWithStale_ GhcSessionDeps file
634638
(HAR{refMap=rf}, _) <- useWithStale_ GetHieAst file
635639

636-
-- When possible, rely on the haddocks embedded in our interface files
637-
-- This creates problems on ghc-lib, see comment on 'getDocumentationTryGhc'
638-
#if !defined(GHC_LIB)
639-
let parsedDeps = []
640-
#else
641-
deps <- fromMaybe (TransitiveDependencies [] [] []) <$> use GetDependencies file
642-
let tdeps = transitiveModuleDeps deps
643-
parsedDeps <- uses_ GetParsedModule tdeps
644-
#endif
645-
646-
dkMap <- liftIO $ mkDocMap hsc parsedDeps rf tc
640+
dkMap <- liftIO $ mkDocMap hsc rf tc
647641
return ([],Just dkMap)
648642

649643
-- | Persistent rule to ensure that hover doesn't block on startup
@@ -662,7 +656,7 @@ readHieFileForSrcFromDisk file = do
662656
readHieFileFromDisk :: FilePath -> ExceptT SomeException IdeAction HieFile
663657
readHieFileFromDisk hie_loc = do
664658
nc <- asks ideNc
665-
log <- asks $ L.logInfo . logger
659+
log <- asks $ L.logDebug . logger
666660
res <- liftIO $ tryAny $ loadHieFile (mkUpdater nc) hie_loc
667661
liftIO . log $ either (const $ "FAILED LOADING HIE FILE FOR:" <> T.pack (show hie_loc))
668662
(const $ "SUCCEEDED LOADING HIE FILE FOR:" <> T.pack (show hie_loc))
@@ -835,7 +829,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ \GetModIfaceFromDiskAndInd
835829
Left err -> fail $ "failed to read .hie file " ++ show hie_loc ++ ": " ++ displayException err
836830
-- can just re-index the file we read from disk
837831
Right hf -> liftIO $ do
838-
L.logInfo (logger se) $ "Re-indexing hie file for" <> T.pack (show f)
832+
L.logDebug (logger se) $ "Re-indexing hie file for" <> T.pack (show f)
839833
indexHieFile se ms f hash hf
840834

841835
let fp = hiFileFingerPrint x
@@ -921,7 +915,6 @@ generateCoreRule =
921915

922916
getModIfaceRule :: Rules ()
923917
getModIfaceRule = defineEarlyCutoff $ \GetModIface f -> do
924-
#if !defined(GHC_LIB)
925918
fileOfInterest <- use_ IsFileOfInterest f
926919
res@(_,(_,mhmi)) <- case fileOfInterest of
927920
IsFOI status -> do
@@ -948,13 +941,6 @@ getModIfaceRule = defineEarlyCutoff $ \GetModIface f -> do
948941
compiledLinkables <- getCompiledLinkables <$> getIdeGlobalAction
949942
liftIO $ modifyVar_ compiledLinkables $ \old -> pure $ extendModuleEnv old mod time
950943
pure res
951-
#else
952-
tm <- use_ TypeCheck f
953-
hsc <- hscEnv <$> use_ GhcSessionDeps f
954-
(diags, !hiFile) <- liftIO $ compileToObjCodeIfNeeded hsc Nothing (error "can't compile with ghc-lib") tm
955-
let fp = hiFileFingerPrint <$> hiFile
956-
return (fp, (diags, hiFile))
957-
#endif
958944

959945
getModIfaceWithoutLinkableRule :: Rules ()
960946
getModIfaceWithoutLinkableRule = defineEarlyCutoff $ \GetModIfaceWithoutLinkable f -> do

0 commit comments

Comments
 (0)