Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -132,7 +132,13 @@
hPutStrLn stderr $ "Current directory: " ++ d
hPutStrLn stderr $ "Operating system: " ++ os
args <- getArgs
hPutStrLn stderr $ "Arguments: " ++ show args
let args' = case parsedArgs of
Ghcide GhcideArguments{..}
-- If no --cwd is given, assume the current working directory as the --cwd
| isNothing argsCwd -> args ++ ["--cwd", argsInitialWorkingDirectory]
_ -> args

hPutStrLn stderr $ "Arguments: " ++ show args'
hPutStrLn stderr $ "Cradle directory: " ++ cradleRootDir cradle
hPutStrLn stderr $ "Cradle type: " ++ show (actionName (cradleOptsProg cradle))
programsOfInterest <- findProgramVersions
Expand Down Expand Up @@ -162,7 +168,7 @@
liftIO $ hPutStrLn stderr $ "Launching haskell-language-server exe at:" ++ e

#ifdef mingw32_HOST_OS
liftIO $ callProcess e args
liftIO $ callProcess e args'
#else

let Cradle { cradleOptsProg = CradleAction { runGhcCmd } } = cradle
Expand All @@ -177,7 +183,7 @@

env <- Map.fromList <$> liftIO getEnvironment
let newEnv = Map.insert "GHC_BIN" ghcBinary $ Map.insert "GHC_LIBDIR" libdir env
liftIO $ executeFile e True args (Just (Map.toList newEnv))
liftIO $ executeFile e True args' (Just (Map.toList newEnv))
#endif


Expand Down
37 changes: 21 additions & 16 deletions src/Ide/Arguments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Ide.Logger (Priority (..))
import Ide.Types (IdePlugins)
import Options.Applicative
import Paths_haskell_language_server
import System.Directory (getCurrentDirectory)
import System.Environment

-- ---------------------------------------------------------------------
Expand All @@ -38,18 +39,19 @@ data Arguments
| PrintLibDir

data GhcideArguments = GhcideArguments
{ argsCommand :: Command
, argsCwd :: Maybe FilePath
, argsShakeProfiling :: Maybe FilePath
, argsTesting :: Bool
, argsExamplePlugin :: Bool
, argsLogLevel :: Priority
, argsLogFile :: Maybe String
{ argsCommand :: Command
, argsCwd :: Maybe FilePath
, argsShakeProfiling :: Maybe FilePath
, argsTesting :: Bool
, argsExamplePlugin :: Bool
, argsLogLevel :: Priority
, argsLogFile :: Maybe String
-- ^ the minimum log level to show
, argsLogStderr :: Bool
, argsLogClient :: Bool
, argsThreads :: Int
, argsProjectGhcVersion :: Bool
, argsLogStderr :: Bool
, argsLogClient :: Bool
, argsThreads :: Int
, argsProjectGhcVersion :: Bool
, argsInitialWorkingDirectory :: FilePath
} deriving Show

data PrintVersion
Expand All @@ -62,9 +64,11 @@ data BiosAction
deriving (Show, Eq, Ord)

getArguments :: String -> IdePlugins IdeState -> IO Arguments
getArguments exeName plugins = execParser opts
getArguments exeName plugins = do
cwd <- getCurrentDirectory
execParser (opts cwd)
where
opts = info ((
opts cwd = info ((
VersionMode <$> printVersionParser exeName
<|> probeToolsParser exeName
<|> hsubparser
Expand All @@ -74,7 +78,7 @@ getArguments exeName plugins = execParser opts
)
<|> listPluginsParser
<|> BiosMode <$> biosParser
<|> Ghcide <$> arguments plugins
<|> Ghcide <$> arguments cwd plugins
<|> flag' PrintLibDir (long "print-libdir" <> help "Print project GHCs libdir")
)
<**> helper)
Expand Down Expand Up @@ -115,8 +119,8 @@ listPluginsParser =
flag' ListPluginsMode
(long "list-plugins" <> help "List all available plugins")

arguments :: IdePlugins IdeState -> Parser GhcideArguments
arguments plugins = GhcideArguments
arguments :: FilePath -> IdePlugins IdeState -> Parser GhcideArguments
arguments cwd plugins = GhcideArguments
<$> (commandP plugins <|> lspCommand <|> checkCommand)
<*> optional (strOption $ long "cwd" <> metavar "DIR"
<> help "Change to this directory")
Expand Down Expand Up @@ -186,6 +190,7 @@ arguments plugins = GhcideArguments
)
<*> switch (long "project-ghc-version"
<> help "Work out the project GHC version and print it")
<*> pure cwd
where
lspCommand = LSP <$ flag' True (long "lsp" <> help "Start talking to an LSP server")
checkCommand = Check <$> many (argument str (metavar "FILES/DIRS..."))
Expand Down
Loading