Skip to content

Commit

Permalink
Add support for multi unit argument syntax (#3462)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wz1000 authored Nov 23, 2023
1 parent c3fcc3e commit 7db6215
Show file tree
Hide file tree
Showing 28 changed files with 610 additions and 240 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
39 changes: 19 additions & 20 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ import Ide.Logger (Doc, Logger (Logger),
Recorder (logger_),
WithPriority (WithPriority),
cmapWithPrio,
makeDefaultStderrRecorder,
toCologActionWithPrio)
makeDefaultStderrRecorder)
import Ide.Plugin.Config (Config)
import Ide.Types (IdePlugins (IdePlugins))
import Language.LSP.Protocol.Message (Method (Method_Initialize),
Expand Down Expand Up @@ -83,8 +82,8 @@ main = do
putStrLn "Tool versions found on the $PATH"
putStrLn $ showProgramVersionOfInterest programsOfInterest
putStrLn "Tool versions in your project"
cradle <- findProjectCradle' False
ghcVersion <- runExceptT $ getRuntimeGhcVersion' recorder cradle
cradle <- findProjectCradle' recorder False
ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle
putStrLn $ showProgramVersion "ghc" $ mkVersion =<< eitherToMaybe ghcVersion

VersionMode PrintVersion ->
Expand All @@ -94,10 +93,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,15 +115,15 @@ 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

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

runExceptT $ do
ghcVersion <- getRuntimeGhcVersion' recorder cradle
ghcVersion <- getRuntimeGhcVersion' cradle
liftIO $ hPutStrLn stderr $ "Project GHC version: " ++ ghcVersion

let
Expand All @@ -172,10 +171,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 All @@ -192,8 +191,8 @@ cradleResult cradleName CradleNone = throwE $ NoneCradleGhcVersion cradleName

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

-- See if the tool is installed
Expand All @@ -204,7 +203,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 +213,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 +229,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 7db6215

Please sign in to comment.