Skip to content

Commit b795a37

Browse files
Merge branch 'master' into harder_hlint_fixes
2 parents 045ecb4 + 45d58fb commit b795a37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+743
-364
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/.hlint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
#
118118
- functions:
119119
# Things that are unsafe in Haskell base library
120-
- {name: unsafeInterleaveIO, within: []}
120+
- {name: unsafeInterleaveIO, within: [Development.IDE.LSP.LanguageServer]}
121121
- {name: unsafeDupablePerformIO, within: []}
122122
- {name: unsafeCoerce, within: [Ide.Plugin.Eval.Code]}
123123
# Things that are a bit dangerous in the GHC API

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/exe/Main.hs

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Development.IDE.Core.OfInterest (kick)
2020
import Development.IDE.Core.Rules (mainRule)
2121
import qualified Development.IDE.Plugin.HLS.GhcIde as GhcIde
2222
import qualified Development.IDE.Plugin.Test as Test
23-
import Development.IDE.Session (setInitialDynFlags, getHieDbLoc, runWithDb)
23+
import Development.IDE.Session (setInitialDynFlags, getHieDbLoc)
2424
import Development.IDE.Types.Options
2525
import qualified Development.IDE.Main as Main
2626
import Development.Shake (ShakeOptions(shakeThreads))
@@ -56,9 +56,6 @@ main = do
5656

5757
whenJust argsCwd IO.setCurrentDirectory
5858

59-
dir <- IO.getCurrentDirectory
60-
dbLoc <- getHieDbLoc dir
61-
6259
-- lock to avoid overlapping output on stdout
6360
lock <- newLock
6461
let logger = Logger $ \pri msg -> when (pri >= logLevel) $ withLock lock $
@@ -67,7 +64,9 @@ main = do
6764

6865
case argFilesOrCmd of
6966
DbCmd opts cmd -> do
70-
mlibdir <- setInitialDynFlags
67+
dir <- IO.getCurrentDirectory
68+
dbLoc <- getHieDbLoc dir
69+
mlibdir <- setInitialDynFlags def
7170
case mlibdir of
7271
Nothing -> exitWith $ ExitFailure 1
7372
Just libdir -> runCommand libdir opts{database = dbLoc} cmd
@@ -80,40 +79,39 @@ main = do
8079
hPutStrLn stderr "If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
8180
_ -> return ()
8281

83-
runWithDb dbLoc $ \hiedb hiechan ->
84-
Main.defaultMain (Main.defArguments hiedb hiechan)
85-
{Main.argFiles = case argFilesOrCmd of
86-
Typecheck x | not argLSP -> Just x
87-
_ -> Nothing
88-
89-
,Main.argsLogger = logger
90-
91-
,Main.argsRules = do
92-
-- install the main and ghcide-plugin rules
93-
mainRule
94-
-- install the kick action, which triggers a typecheck on every
95-
-- Shake database restart, i.e. on every user edit.
96-
unless argsDisableKick $
97-
action kick
98-
99-
,Main.argsHlsPlugins =
100-
pluginDescToIdePlugins $
101-
GhcIde.descriptors
102-
++ [Test.blockCommandDescriptor "block-command" | argsTesting]
103-
104-
,Main.argsGhcidePlugin = if argsTesting
105-
then Test.plugin
106-
else mempty
107-
108-
,Main.argsIdeOptions = \(fromMaybe def -> config) sessionLoader ->
109-
let defOptions = defaultIdeOptions sessionLoader
110-
in defOptions
111-
{ optShakeProfiling = argsShakeProfiling
112-
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
113-
, optTesting = IdeTesting argsTesting
114-
, optShakeOptions = (optShakeOptions defOptions){shakeThreads = argsThreads}
115-
, optCheckParents = pure $ checkParents config
116-
, optCheckProject = pure $ checkProject config
117-
}
118-
}
82+
Main.defaultMain def
83+
{Main.argFiles = case argFilesOrCmd of
84+
Typecheck x | not argLSP -> Just x
85+
_ -> Nothing
86+
87+
,Main.argsLogger = logger
88+
89+
,Main.argsRules = do
90+
-- install the main and ghcide-plugin rules
91+
mainRule
92+
-- install the kick action, which triggers a typecheck on every
93+
-- Shake database restart, i.e. on every user edit.
94+
unless argsDisableKick $
95+
action kick
96+
97+
,Main.argsHlsPlugins =
98+
pluginDescToIdePlugins $
99+
GhcIde.descriptors
100+
++ [Test.blockCommandDescriptor "block-command" | argsTesting]
101+
102+
,Main.argsGhcidePlugin = if argsTesting
103+
then Test.plugin
104+
else mempty
105+
106+
,Main.argsIdeOptions = \(fromMaybe def -> config) sessionLoader ->
107+
let defOptions = defaultIdeOptions sessionLoader
108+
in defOptions
109+
{ optShakeProfiling = argsShakeProfiling
110+
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
111+
, optTesting = IdeTesting argsTesting
112+
, optShakeOptions = (optShakeOptions defOptions){shakeThreads = argsThreads}
113+
, optCheckParents = pure $ checkParents config
114+
, optCheckProject = pure $ checkProject config
115+
}
116+
}
119117

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: 22 additions & 14 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,30 +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
115-
cradle <- maybe (HieBios.loadImplicitCradle $ addTrailingPathSeparator dir) HieBios.loadCradle hieYaml
117+
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios.loadCradle hieYaml
118+
hPutStrLn stderr $ "setInitialDynFlags cradle: " ++ show cradle
116119
libDirRes <- getRuntimeGhcLibDir cradle
117-
libdir <- case libDirRes of
120+
case libDirRes of
118121
CradleSuccess libdir -> pure $ Just $ LibDir libdir
119122
CradleFail err -> do
120123
hPutStrLn stderr $ "Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
121124
pure Nothing
122125
CradleNone -> do
123126
hPutStrLn stderr "Couldn't load cradle (CradleNone)"
124127
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
125133
dynFlags <- mapM dynFlagsForPrinting libdir
126134
mapM_ setUnsafeGlobalDynFlags dynFlags
127135
pure libdir
@@ -176,7 +184,7 @@ getHieDbLoc dir = do
176184
-- components mapping to the same hie.yaml file are mapped to the same
177185
-- HscEnv which is updated as new components are discovered.
178186
loadSession :: FilePath -> IO (Action IdeGhcSession)
179-
loadSession = loadSessionWithOptions defaultLoadingOptions
187+
loadSession = loadSessionWithOptions def
180188

181189
loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession)
182190
loadSessionWithOptions SessionLoadingOptions{..} dir = do
@@ -613,7 +621,7 @@ should be filtered out, such that we dont have to re-compile everything.
613621
-- For the exact reason, see Note [Avoiding bad interface files].
614622
setCacheDirs :: MonadIO m => Logger -> CacheDirs -> DynFlags -> m DynFlags
615623
setCacheDirs logger CacheDirs{..} dflags = do
616-
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)
617625
pure $ dflags
618626
& maybe id setHiDir hiCacheDir
619627
& maybe id setHieDir hieCacheDir

0 commit comments

Comments
 (0)