Skip to content
New issue

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

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

Already on GitHub? Sign in 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
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
@@ -1,4 +1,4 @@
{-# LANGUAGE CPP #-}

Check warning on line 1 in exe/Wrapper.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Main: Use module export list ▫︎ Found: "module Main where" ▫︎ Perhaps: "module Main (\n module Main\n ) where" ▫︎ Note: an explicit list is usually better
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Expand Down Expand Up @@ -51,8 +51,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@

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

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