Skip to content

Commit

Permalink
Add support for the multi unit argument syntax introduced in GHC 9.4: h…
Browse files Browse the repository at this point in the history
…ttps://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
  • Loading branch information
wz1000 committed Nov 21, 2023
1 parent c3fcc3e commit f38beda
Show file tree
Hide file tree
Showing 20 changed files with 557 additions and 212 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packages:
./plugins/hls-refactor-plugin
./plugins/hls-overloaded-record-dot-plugin

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

tests: True
test-show-details: direct
Expand Down
26 changes: 13 additions & 13 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ main = do
putStrLn "Tool versions found on the $PATH"
putStrLn $ showProgramVersionOfInterest programsOfInterest
putStrLn "Tool versions in your project"
cradle <- findProjectCradle' False
cradle <- findProjectCradle' recorder False
ghcVersion <- runExceptT $ getRuntimeGhcVersion' recorder cradle
putStrLn $ showProgramVersion "ghc" $ mkVersion =<< eitherToMaybe ghcVersion

Expand All @@ -94,10 +94,10 @@ main = do
putStrLn haskellLanguageServerNumericVersion

BiosMode PrintCradleType ->
print =<< findProjectCradle
print =<< findProjectCradle recorder
PrintLibDir -> do
cradle <- findProjectCradle' False
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
cradle <- findProjectCradle' recorder False
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
putStr libdir
_ -> launchHaskellLanguageServer recorder args >>= \case
Right () -> pure ()
Expand All @@ -116,7 +116,7 @@ launchHaskellLanguageServer recorder parsedArgs = do
d <- getCurrentDirectory

-- search for the project cradle type
cradle <- findProjectCradle
cradle <- findProjectCradle recorder

-- Get the root directory from the cradle
setCurrentDirectory $ cradleRootDir cradle
Expand Down Expand Up @@ -172,10 +172,10 @@ launchHaskellLanguageServer recorder parsedArgs = do

let cradleName = actionName (cradleOptsProg cradle)
-- we need to be compatible with NoImplicitPrelude
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)"])
ghcBinary <- liftIO (fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-ignore-dot-ghci", "-e", "Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)"])
>>= cradleResult cradleName

libdir <- liftIO (HieBios.getRuntimeGhcLibDir (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle)
libdir <- liftIO (HieBios.getRuntimeGhcLibDir cradle)
>>= cradleResult cradleName

env <- Map.fromList <$> liftIO getEnvironment
Expand Down Expand Up @@ -204,7 +204,7 @@ getRuntimeGhcVersion' recorder cradle = do
Direct -> checkToolExists "ghc"
_ -> pure ()

ghcVersionRes <- liftIO $ HieBios.getRuntimeGhcVersion (toCologActionWithPrio (cmapWithPrio pretty recorder)) cradle
ghcVersionRes <- liftIO $ HieBios.getRuntimeGhcVersion cradle
cradleResult cradleName ghcVersionRes

where
Expand All @@ -214,11 +214,11 @@ getRuntimeGhcVersion' recorder cradle = do
Just _ -> pure ()
Nothing -> throwE $ ToolRequirementMissing exe (actionName (cradleOptsProg cradle))

findProjectCradle :: IO (Cradle Void)
findProjectCradle = findProjectCradle' True
findProjectCradle :: Recorder (WithPriority (Doc ())) -> IO (Cradle Void)
findProjectCradle recorder = findProjectCradle' recorder True

findProjectCradle' :: Bool -> IO (Cradle Void)
findProjectCradle' log = do
findProjectCradle' :: Recorder (WithPriority (Doc ())) -> Bool -> IO (Cradle Void)
findProjectCradle' recorder log = do
d <- getCurrentDirectory

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

Session.loadCradle def hieYaml d
Session.loadCradle def (cmapWithPrio pretty recorder) hieYaml d

trim :: String -> String
trim s = case lines s of
Expand Down
11 changes: 4 additions & 7 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ library
, Glob
, haddock-library >=1.8 && <1.12
, hashable
, hie-bios ==0.12.1
, hie-bios ==0.13.1
, hie-compat ^>=0.3.0.0
, hiedb >=0.4.4 && <0.4.5
, hls-graph ==2.4.0.0
, hls-plugin-api ==2.4.0.0
, implicit-hie <0.1.3
, implicit-hie-cradle ^>=0.3.0.5 || ^>=0.5
, implicit-hie >= 0.1.4.0 && < 0.1.5
, lens
, list-t
, lsp ^>=2.3.0.0
Expand Down Expand Up @@ -111,10 +110,6 @@ library
, unordered-containers >=0.2.10.0
, vector

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

Expand Down Expand Up @@ -165,6 +160,7 @@ library
Development.IDE.Core.UseStale
Development.IDE.GHC.Compat
Development.IDE.GHC.Compat.Core
Development.IDE.GHC.Compat.CmdLine
Development.IDE.GHC.Compat.Env
Development.IDE.GHC.Compat.Iface
Development.IDE.GHC.Compat.Logger
Expand Down Expand Up @@ -197,6 +193,7 @@ library
Development.IDE.Plugin.TypeLenses
Development.IDE.Session
Development.IDE.Session.Diagnostics
Development.IDE.Session.Implicit
Development.IDE.Spans.AtPoint
Development.IDE.Spans.Common
Development.IDE.Spans.Documentation
Expand Down
Loading

0 comments on commit f38beda

Please sign in to comment.