Skip to content

Commit 0d80826

Browse files
committed
Alternate implementation of selecting Project Root
1 parent 89ed1a6 commit 0d80826

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

ghcide/exe/Main.hs

+4-7
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,14 @@ main = withTelemetryLogger $ \telemetryLogger -> do
5050
if argsVersion then ghcideVersion >>= putStrLn >> exitSuccess
5151
else hPutStrLn stderr {- see WARNING above -} =<< ghcideVersion
5252

53-
-- getHieDbLoc takes a directory path (the project root) and hashes it to find the location of the hiedb
54-
-- when running commands directly from GHCIDE we need to provide the ABSOLUTE path to the project root (that's what HLS uses)
55-
argsCwd <-case argsCwd of
56-
Nothing -> IO.getCurrentDirectory
57-
Just root -> IO.setCurrentDirectory root >> IO.getCurrentDirectory
58-
5953
let logPriority = if argsVerbose then Debug else Info
6054
arguments = if argsTesting then Main.testing else Main.defaultArguments logPriority
6155

6256
Main.defaultMain arguments
63-
{ Main.argsProjectRoot = Just argsCwd
57+
{ Main.argsProjectRoot = case argsCwd of
58+
Nothing -> IO.getCurrentDirectory
59+
-- if passed a directory we must set it
60+
Just root -> IO.setCurrentDirectory root >> IO.getCurrentDirectory
6461
, Main.argCommand = argsCommand
6562
,Main.argsLogger = Main.argsLogger arguments <> pure telemetryLogger
6663

ghcide/src/Development/IDE/Main.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ commandP plugins =
167167

168168

169169
data Arguments = Arguments
170-
{ argsProjectRoot :: Maybe FilePath
170+
{ argsProjectRoot :: IO FilePath
171171
, argsOTMemoryProfiling :: Bool
172172
, argCommand :: Command
173173
, argsLogger :: IO Logger
@@ -190,7 +190,7 @@ instance Default Arguments where
190190

191191
defaultArguments :: Priority -> Arguments
192192
defaultArguments priority = Arguments
193-
{ argsProjectRoot = Nothing
193+
{ argsProjectRoot = IO.getCurrentDirectory
194194
, argsOTMemoryProfiling = False
195195
, argCommand = LSP
196196
, argsLogger = stderrLogger priority
@@ -383,7 +383,7 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger
383383

384384
unless (null failed) (exitWith $ ExitFailure (length failed))
385385
Db opts cmd -> do
386-
root <- maybe IO.getCurrentDirectory return argsProjectRoot
386+
root <- argsProjectRoot
387387
dbLoc <- getHieDbLoc root
388388
hPutStrLn stderr $ "Using hiedb at: " ++ dbLoc
389389
mlibdir <- setInitialDynFlags logger root def
@@ -392,8 +392,7 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger
392392
Just libdir -> HieDb.runCommand libdir opts{HieDb.database = dbLoc} cmd
393393

394394
Custom (IdeCommand c) -> do
395-
root <- maybe IO.getCurrentDirectory return argsProjectRoot
396-
dbLoc <- getHieDbLoc root
395+
dbLoc <- argsProjectRoot >>= getHieDbLoc
397396
runWithDb logger dbLoc $ \hiedb hieChan -> do
398397
vfs <- makeVFSHandle
399398
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions "."

0 commit comments

Comments
 (0)