diff --git a/ghcide/exe/Main.hs b/ghcide/exe/Main.hs index 8385a3d179..c743231255 100644 --- a/ghcide/exe/Main.hs +++ b/ghcide/exe/Main.hs @@ -50,9 +50,8 @@ main = withTelemetryLogger $ \telemetryLogger -> do if argsVersion then ghcideVersion >>= putStrLn >> exitSuccess else hPutStrLn stderr {- see WARNING above -} =<< ghcideVersion - -- getHieDbLoc takes a directory path (the project root) and hashes it to find the location of the hiedb - -- when running commands directly from GHCIDE we need to provide the ABSOLUTE path to the project root (that's what HLS uses) - argsCwd <-case argsCwd of + -- if user uses --cwd option we need to make this path absolute (and set the current directory to it) + argsCwd <- case argsCwd of Nothing -> IO.getCurrentDirectory Just root -> IO.setCurrentDirectory root >> IO.getCurrentDirectory diff --git a/ghcide/src/Development/IDE/Main.hs b/ghcide/src/Development/IDE/Main.hs index 3c381bcc72..7d89e3a909 100644 --- a/ghcide/src/Development/IDE/Main.hs +++ b/ghcide/src/Development/IDE/Main.hs @@ -319,7 +319,7 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger hieChan dumpSTMStats Check argFiles -> do - dir <- IO.getCurrentDirectory + dir <- maybe IO.getCurrentDirectory return argsProjectRoot dbLoc <- getHieDbLoc dir runWithDb logger dbLoc $ \hiedb hieChan -> do -- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error