@@ -124,12 +124,12 @@ import Text.Printf (printf)
124
124
125
125
data Command
126
126
= Check [FilePath ] -- ^ Typecheck some paths and print diagnostics. Exit code is the number of failures
127
- | Db { projectRoot :: FilePath , hieOptions :: HieDb. Options , hieCommand :: HieDb. Command}
127
+ | Db { hieOptions :: HieDb. Options , hieCommand :: HieDb. Command}
128
128
-- ^ Run a command in the hiedb
129
129
| LSP -- ^ Run the LSP server
130
130
| PrintExtensionSchema
131
131
| PrintDefaultConfig
132
- | Custom { projectRoot :: FilePath , ideCommand :: IdeCommand IdeState } -- ^ User defined
132
+ | Custom { ideCommand :: IdeCommand IdeState } -- ^ User defined
133
133
deriving Show
134
134
135
135
@@ -144,7 +144,7 @@ isLSP _ = False
144
144
commandP :: IdePlugins IdeState -> Parser Command
145
145
commandP plugins =
146
146
hsubparser(command " typecheck" (info (Check <$> fileCmd) fileInfo)
147
- <> command " hiedb" (info (Db " . " <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
147
+ <> command " hiedb" (info (Db <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
148
148
<> command " lsp" (info (pure LSP <**> helper) lspInfo)
149
149
<> command " vscode-extension-schema" extensionSchemaCommand
150
150
<> command " generate-default-config" generateDefaultConfigCommand
@@ -163,13 +163,14 @@ commandP plugins =
163
163
(fullDesc <> progDesc " Print config supported by the server with default values" )
164
164
165
165
pluginCommands = mconcat
166
- [ command (T. unpack pId) (Custom " . " <$> p)
166
+ [ command (T. unpack pId) (Custom <$> p)
167
167
| (PluginId pId, PluginDescriptor {pluginCli = Just p}) <- ipMap plugins
168
168
]
169
169
170
170
171
171
data Arguments = Arguments
172
- { argsOTMemoryProfiling :: Bool
172
+ { argsProjectRoot :: Maybe FilePath
173
+ , argsOTMemoryProfiling :: Bool
173
174
, argCommand :: Command
174
175
, argsLogger :: IO Logger
175
176
, argsRules :: Rules ()
@@ -191,7 +192,8 @@ instance Default Arguments where
191
192
192
193
defaultArguments :: Priority -> Arguments
193
194
defaultArguments priority = Arguments
194
- { argsOTMemoryProfiling = False
195
+ { argsProjectRoot = Nothing
196
+ , argsOTMemoryProfiling = False
195
197
, argCommand = LSP
196
198
, argsLogger = stderrLogger priority
197
199
, argsRules = mainRule def >> action kick
@@ -319,7 +321,7 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger
319
321
hieChan
320
322
dumpSTMStats
321
323
Check argFiles -> do
322
- dir <- IO. getCurrentDirectory
324
+ dir <- maybe IO. getCurrentDirectory return argsProjectRoot
323
325
dbLoc <- getHieDbLoc dir
324
326
runWithDb logger dbLoc $ \ hiedb hieChan -> do
325
327
-- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
@@ -382,17 +384,19 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger
382
384
measureMemory logger [keys] consoleObserver values
383
385
384
386
unless (null failed) (exitWith $ ExitFailure (length failed))
385
- Db dir opts cmd -> do
386
- dbLoc <- getHieDbLoc dir
387
+ Db opts cmd -> do
388
+ root <- maybe IO. getCurrentDirectory return argsProjectRoot
389
+ dbLoc <- getHieDbLoc root
387
390
hPutStrLn stderr $ " Using hiedb at: " ++ dbLoc
388
- mlibdir <- setInitialDynFlags logger dir def
391
+ mlibdir <- setInitialDynFlags logger root def
389
392
rng <- newStdGen
390
393
case mlibdir of
391
394
Nothing -> exitWith $ ExitFailure 1
392
395
Just libdir -> retryOnSqliteBusy logger rng (HieDb. runCommand libdir opts{HieDb. database = dbLoc} cmd)
393
396
394
- Custom projectRoot (IdeCommand c) -> do
395
- dbLoc <- getHieDbLoc projectRoot
397
+ Custom (IdeCommand c) -> do
398
+ root <- maybe IO. getCurrentDirectory return argsProjectRoot
399
+ dbLoc <- getHieDbLoc root
396
400
runWithDb logger dbLoc $ \ hiedb hieChan -> do
397
401
vfs <- makeVFSHandle
398
402
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions " ."
0 commit comments