Skip to content

Commit 7db6215

Browse files
authored
Add support for multi unit argument syntax (#3462)
* Add support for the multi unit argument syntax introduced in GHC 9.4: https://downloads.haskell.org/ghc/9.4.4/docs/users_guide/using.html#multiple-home-units We now support arguments of the form ``` -unit @unitA -unit @unitb ``` where the response files `unitA` and `unitB` contain the actual list of arguments for that unit: ``` -this-unit-id a-0.1.0.0 -i -isrc A1 A2 ``` Also refactor the session loader and simplify it. Also adds error messages on GHC 9.4 if the units are not closed (#3422). fixes Fix closure check session-loader: override old units with new in multi-unit support Remove implicit-hie session-loader: remember which files caused old components to be loaded, and also pass them on to hie-bios so it can in turn pass them to `cabal repl` when loading newer components. This allows us to create valid set of build flags encompassing both the old and new components, and the closure of all components in between. The observation is that if you want to load some components X, Y, Z and so on, cabal repl X Y Z ... will be more likely to give you a valid multi component build plan/flags than cabal repl all, or any way of combining the results of cabal repl X, cabal repl Y ... Use new hie-bios Move implicit cradles to HLS Fix build on 9.0 Werror Improve handling of specialTarget * hie-bios doesn't mention the component name in the message anymore * stack fixes * wrapper: remove unused argument * werror * werror * Implicit cradle: match implicit-hie-cradle logic * Fix eval plugin * ignore multi unit tests on 9.2 * Some fixes for 9.2 * Add hie.yaml for call-hierarchy-plugin tests * Add hie.yaml for explicit-record-fields-plugin * Add hie.yaml for hls-overloaded-record-dot-plugin
1 parent c3fcc3e commit 7db6215

File tree

28 files changed

+610
-240
lines changed

28 files changed

+610
-240
lines changed

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ packages:
3535
./plugins/hls-refactor-plugin
3636
./plugins/hls-overloaded-record-dot-plugin
3737

38-
index-state: 2023-11-13T12:07:58Z
38+
index-state: 2023-11-14T11:26:13Z
3939

4040
tests: True
4141
test-show-details: direct

exe/Wrapper.hs

+19-20
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import Ide.Logger (Doc, Logger (Logger),
5151
Recorder (logger_),
5252
WithPriority (WithPriority),
5353
cmapWithPrio,
54-
makeDefaultStderrRecorder,
55-
toCologActionWithPrio)
54+
makeDefaultStderrRecorder)
5655
import Ide.Plugin.Config (Config)
5756
import Ide.Types (IdePlugins (IdePlugins))
5857
import Language.LSP.Protocol.Message (Method (Method_Initialize),
@@ -83,8 +82,8 @@ main = do
8382
putStrLn "Tool versions found on the $PATH"
8483
putStrLn $ showProgramVersionOfInterest programsOfInterest
8584
putStrLn "Tool versions in your project"
86-
cradle <- findProjectCradle' False
87-
ghcVersion <- runExceptT $ getRuntimeGhcVersion' recorder cradle
85+
cradle <- findProjectCradle' recorder False
86+
ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle
8887
putStrLn $ showProgramVersion "ghc" $ mkVersion =<< eitherToMaybe ghcVersion
8988

9089
VersionMode PrintVersion ->
@@ -94,10 +93,10 @@ main = do
9493
putStrLn haskellLanguageServerNumericVersion
9594

9695
BiosMode PrintCradleType ->
97-
print =<< findProjectCradle
96+
print =<< findProjectCradle recorder
9897
PrintLibDir -> do
99-
cradle <- findProjectCradle' False
100-
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
98+
cradle <- findProjectCradle' recorder False
99+
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
101100
putStr libdir
102101
_ -> launchHaskellLanguageServer recorder args >>= \case
103102
Right () -> pure ()
@@ -116,15 +115,15 @@ launchHaskellLanguageServer recorder parsedArgs = do
116115
d <- getCurrentDirectory
117116

118117
-- search for the project cradle type
119-
cradle <- findProjectCradle
118+
cradle <- findProjectCradle recorder
120119

121120
-- Get the root directory from the cradle
122121
setCurrentDirectory $ cradleRootDir cradle
123122

124123
case parsedArgs of
125124
Ghcide GhcideArguments{..} ->
126125
when argsProjectGhcVersion $ do
127-
runExceptT (getRuntimeGhcVersion' recorder cradle) >>= \case
126+
runExceptT (getRuntimeGhcVersion' cradle) >>= \case
128127
Right ghcVersion -> putStrLn ghcVersion >> exitSuccess
129128
Left err -> T.putStrLn (prettyError err NoShorten) >> exitFailure
130129
_ -> pure ()
@@ -147,7 +146,7 @@ launchHaskellLanguageServer recorder parsedArgs = do
147146
hPutStrLn stderr "Consulting the cradle to get project GHC version..."
148147

149148
runExceptT $ do
150-
ghcVersion <- getRuntimeGhcVersion' recorder cradle
149+
ghcVersion <- getRuntimeGhcVersion' cradle
151150
liftIO $ hPutStrLn stderr $ "Project GHC version: " ++ ghcVersion
152151

153152
let
@@ -172,10 +171,10 @@ launchHaskellLanguageServer recorder parsedArgs = do
172171

173172
let cradleName = actionName (cradleOptsProg cradle)
174173
-- we need to be compatible with NoImplicitPrelude
175-
ghcBinary <- liftIO (fmap trim <$> runGhcCmd (toCologActionWithPrio (cmapWithPrio pretty recorder)) ["-v0", "-package-env=-", "-ignore-dot-ghci", "-e", "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"])
174+
ghcBinary <- liftIO (fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-ignore-dot-ghci", "-e", "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"])
176175
>>= cradleResult cradleName
177176

178-
libdir <- liftIO (HieBios.getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle)
177+
libdir <- liftIO (HieBios.getRuntimeGhcLibDir cradle)
179178
>>= cradleResult cradleName
180179

181180
env <- Map.fromList <$> liftIO getEnvironment
@@ -192,8 +191,8 @@ cradleResult cradleName CradleNone = throwE $ NoneCradleGhcVersion cradleName
192191

193192
-- | Version of 'getRuntimeGhcVersion' that dies if we can't get it, and also
194193
-- checks to see if the tool is missing if it is one of
195-
getRuntimeGhcVersion' :: Recorder (WithPriority (Doc ())) -> Cradle Void -> ExceptT WrapperSetupError IO String
196-
getRuntimeGhcVersion' recorder cradle = do
194+
getRuntimeGhcVersion' :: Cradle Void -> ExceptT WrapperSetupError IO String
195+
getRuntimeGhcVersion' cradle = do
197196
let cradleName = actionName (cradleOptsProg cradle)
198197

199198
-- See if the tool is installed
@@ -204,7 +203,7 @@ getRuntimeGhcVersion' recorder cradle = do
204203
Direct -> checkToolExists "ghc"
205204
_ -> pure ()
206205

207-
ghcVersionRes <- liftIO $ HieBios.getRuntimeGhcVersion (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
206+
ghcVersionRes <- liftIO $ HieBios.getRuntimeGhcVersion cradle
208207
cradleResult cradleName ghcVersionRes
209208

210209
where
@@ -214,11 +213,11 @@ getRuntimeGhcVersion' recorder cradle = do
214213
Just _ -> pure ()
215214
Nothing -> throwE $ ToolRequirementMissing exe (actionName (cradleOptsProg cradle))
216215

217-
findProjectCradle :: IO (Cradle Void)
218-
findProjectCradle = findProjectCradle' True
216+
findProjectCradle :: Recorder (WithPriority (Doc ())) -> IO (Cradle Void)
217+
findProjectCradle recorder = findProjectCradle' recorder True
219218

220-
findProjectCradle' :: Bool -> IO (Cradle Void)
221-
findProjectCradle' log = do
219+
findProjectCradle' :: Recorder (WithPriority (Doc ())) -> Bool -> IO (Cradle Void)
220+
findProjectCradle' recorder log = do
222221
d <- getCurrentDirectory
223222

224223
let initialFp = d </> "a"
@@ -230,7 +229,7 @@ findProjectCradle' log = do
230229
Just yaml -> hPutStrLn stderr $ "Found \"" ++ yaml ++ "\" for \"" ++ initialFp ++ "\""
231230
Nothing -> hPutStrLn stderr "No 'hie.yaml' found. Try to discover the project type!"
232231

233-
Session.loadCradle def hieYaml d
232+
Session.loadCradle def (cmapWithPrio pretty recorder) hieYaml d
234233

235234
trim :: String -> String
236235
trim s = case lines s of

ghcide/ghcide.cabal

+4-7
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@ library
7676
, Glob
7777
, haddock-library >=1.8 && <1.12
7878
, hashable
79-
, hie-bios ==0.12.1
79+
, hie-bios ==0.13.1
8080
, hie-compat ^>=0.3.0.0
8181
, hiedb >=0.4.4 && <0.4.5
8282
, hls-graph ==2.4.0.0
8383
, hls-plugin-api ==2.4.0.0
84-
, implicit-hie <0.1.3
85-
, implicit-hie-cradle ^>=0.3.0.5 || ^>=0.5
84+
, implicit-hie >= 0.1.4.0 && < 0.1.5
8685
, lens
8786
, list-t
8887
, lsp ^>=2.3.0.0
@@ -111,10 +110,6 @@ library
111110
, unordered-containers >=0.2.10.0
112111
, vector
113112

114-
-- implicit-hie 0.1.3.0 introduced an unexpected behavioral change.
115-
-- https://github.com/Avi-D-coder/implicit-hie/issues/50
116-
-- to make sure ghcide behaves in a desirable way, we put implicit-hie
117-
-- fake dependency here.
118113
if os(windows)
119114
build-depends: Win32
120115

@@ -165,6 +160,7 @@ library
165160
Development.IDE.Core.UseStale
166161
Development.IDE.GHC.Compat
167162
Development.IDE.GHC.Compat.Core
163+
Development.IDE.GHC.Compat.CmdLine
168164
Development.IDE.GHC.Compat.Env
169165
Development.IDE.GHC.Compat.Iface
170166
Development.IDE.GHC.Compat.Logger
@@ -197,6 +193,7 @@ library
197193
Development.IDE.Plugin.TypeLenses
198194
Development.IDE.Session
199195
Development.IDE.Session.Diagnostics
196+
Development.IDE.Session.Implicit
200197
Development.IDE.Spans.AtPoint
201198
Development.IDE.Spans.Common
202199
Development.IDE.Spans.Documentation

0 commit comments

Comments
 (0)