@@ -11,7 +11,8 @@ module Development.IDE.Main
11
11
,testing) where
12
12
import Control.Concurrent.Extra (newLock , withLock ,
13
13
withNumCapabilities )
14
- import Control.Concurrent.STM.Stats (atomically , dumpSTMStats )
14
+ import Control.Concurrent.STM.Stats (atomically ,
15
+ dumpSTMStats )
15
16
import Control.Exception.Safe (Exception (displayException ),
16
17
catchAny )
17
18
import Control.Monad.Extra (concatMapM , unless ,
@@ -56,6 +57,7 @@ import Development.IDE.Core.Shake (IdeState (shakeExtras),
56
57
import Development.IDE.Core.Tracing (measureMemory )
57
58
import Development.IDE.Graph (action )
58
59
import Development.IDE.LSP.LanguageServer (runLanguageServer )
60
+ import Development.IDE.Main.HeapStats (withHeapStats )
59
61
import Development.IDE.Plugin (Plugin (pluginHandlers , pluginModifyDynflags , pluginRules ))
60
62
import Development.IDE.Plugin.HLS (asGhcIdePlugin )
61
63
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
@@ -77,12 +79,10 @@ import Development.IDE.Types.Options (IdeGhcSession,
77
79
defaultIdeOptions ,
78
80
optModifyDynFlags ,
79
81
optTesting )
80
- import Development.IDE.Types.Shake (Key (Key ),
81
- fromKeyType )
82
+ import Development.IDE.Types.Shake (Key (Key ), fromKeyType )
82
83
import GHC.Conc (getNumProcessors )
83
84
import GHC.IO.Encoding (setLocaleEncoding )
84
85
import GHC.IO.Handle (hDuplicate )
85
- import Development.IDE.Main.HeapStats (withHeapStats )
86
86
import HIE.Bios.Cradle (findCradle )
87
87
import qualified HieDb.Run as HieDb
88
88
import Ide.Plugin.Config (CheckParents (NeverCheck ),
@@ -122,12 +122,12 @@ import Text.Printf (printf)
122
122
123
123
data Command
124
124
= Check [FilePath ] -- ^ Typecheck some paths and print diagnostics. Exit code is the number of failures
125
- | Db { projectRoot :: FilePath , hieOptions :: HieDb. Options , hieCommand :: HieDb. Command}
125
+ | Db { hieOptions :: HieDb. Options , hieCommand :: HieDb. Command}
126
126
-- ^ Run a command in the hiedb
127
127
| LSP -- ^ Run the LSP server
128
128
| PrintExtensionSchema
129
129
| PrintDefaultConfig
130
- | Custom { projectRoot :: FilePath , ideCommand :: IdeCommand IdeState } -- ^ User defined
130
+ | Custom { ideCommand :: IdeCommand IdeState } -- ^ User defined
131
131
deriving Show
132
132
133
133
@@ -142,7 +142,7 @@ isLSP _ = False
142
142
commandP :: IdePlugins IdeState -> Parser Command
143
143
commandP plugins =
144
144
hsubparser(command " typecheck" (info (Check <$> fileCmd) fileInfo)
145
- <> command " hiedb" (info (Db " . " <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
145
+ <> command " hiedb" (info (Db <$> HieDb. optParser " " True <*> HieDb. cmdParser <**> helper) hieInfo)
146
146
<> command " lsp" (info (pure LSP <**> helper) lspInfo)
147
147
<> command " vscode-extension-schema" extensionSchemaCommand
148
148
<> command " generate-default-config" generateDefaultConfigCommand
@@ -161,13 +161,14 @@ commandP plugins =
161
161
(fullDesc <> progDesc " Print config supported by the server with default values" )
162
162
163
163
pluginCommands = mconcat
164
- [ command (T. unpack pId) (Custom " . " <$> p)
164
+ [ command (T. unpack pId) (Custom <$> p)
165
165
| (PluginId pId, PluginDescriptor {pluginCli = Just p}) <- ipMap plugins
166
166
]
167
167
168
168
169
169
data Arguments = Arguments
170
- { argsOTMemoryProfiling :: Bool
170
+ { argsProjectRoot :: Maybe FilePath
171
+ , argsOTMemoryProfiling :: Bool
171
172
, argCommand :: Command
172
173
, argsLogger :: IO Logger
173
174
, argsRules :: Rules ()
@@ -189,7 +190,8 @@ instance Default Arguments where
189
190
190
191
defaultArguments :: Priority -> Arguments
191
192
defaultArguments priority = Arguments
192
- { argsOTMemoryProfiling = False
193
+ { argsProjectRoot = Nothing
194
+ , argsOTMemoryProfiling = False
193
195
, argCommand = LSP
194
196
, argsLogger = stderrLogger priority
195
197
, argsRules = mainRule def >> action kick
@@ -380,16 +382,18 @@ defaultMain Arguments{..} = flip withHeapStats fun =<< argsLogger
380
382
measureMemory logger [keys] consoleObserver values
381
383
382
384
unless (null failed) (exitWith $ ExitFailure (length failed))
383
- Db dir opts cmd -> do
384
- dbLoc <- getHieDbLoc dir
385
+ Db opts cmd -> do
386
+ root <- maybe IO. getCurrentDirectory return argsProjectRoot
387
+ dbLoc <- getHieDbLoc root
385
388
hPutStrLn stderr $ " Using hiedb at: " ++ dbLoc
386
- mlibdir <- setInitialDynFlags logger dir def
389
+ mlibdir <- setInitialDynFlags logger root def
387
390
case mlibdir of
388
391
Nothing -> exitWith $ ExitFailure 1
389
392
Just libdir -> HieDb. runCommand libdir opts{HieDb. database = dbLoc} cmd
390
393
391
- Custom projectRoot (IdeCommand c) -> do
392
- dbLoc <- getHieDbLoc projectRoot
394
+ Custom (IdeCommand c) -> do
395
+ root <- maybe IO. getCurrentDirectory return argsProjectRoot
396
+ dbLoc <- getHieDbLoc root
393
397
runWithDb logger dbLoc $ \ hiedb hieChan -> do
394
398
vfs <- makeVFSHandle
395
399
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions " ."
0 commit comments