Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for multi unit argument syntax #3462

Merged
merged 13 commits into from
Nov 23, 2023
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -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
39 changes: 19 additions & 20 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
@@ -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),
@@ -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 ->
@@ -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 ()
@@ -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 ()
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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
11 changes: 4 additions & 7 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
@@ -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
@@ -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

@@ -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
@@ -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
Loading