@@ -37,9 +37,7 @@ import Development.IDE.Core.Rules (
3737 )
3838import Development.IDE.Core.Service (initialise , runAction )
3939import Development.IDE.Core.Shake (
40- HieDb ,
4140 IdeState (shakeExtras ),
42- IndexQueue ,
4341 ShakeExtras (state ),
4442 uses ,
4543 )
@@ -49,7 +47,7 @@ import Development.IDE.Plugin (
4947 Plugin (pluginHandlers , pluginRules ),
5048 )
5149import Development.IDE.Plugin.HLS (asGhcIdePlugin )
52- import Development.IDE.Session (SessionLoadingOptions , defaultLoadingOptions , loadSessionWithOptions , setInitialDynFlags )
50+ import Development.IDE.Session (SessionLoadingOptions , defaultLoadingOptions , loadSessionWithOptions , setInitialDynFlags , getHieDbLoc , runWithDb )
5351import Development.IDE.Types.Location (toNormalizedFilePath' )
5452import Development.IDE.Types.Logger (Logger )
5553import Development.IDE.Types.Options (
@@ -77,37 +75,34 @@ data Arguments = Arguments
7775 { argsOTMemoryProfiling :: Bool
7876 , argFiles :: Maybe [FilePath ] -- ^ Nothing: lsp server ; Just: typecheck and exit
7977 , argsLogger :: Logger
80- , argsHiedb :: HieDb
81- , argsHieChan :: IndexQueue
8278 , argsRules :: Rules ()
8379 , argsHlsPlugins :: IdePlugins IdeState
8480 , argsGhcidePlugin :: Plugin Config -- ^ Deprecated
8581 , argsSessionLoadingOptions :: SessionLoadingOptions
8682 , argsIdeOptions :: Maybe Config -> Action IdeGhcSession -> IdeOptions
8783 , argsLspOptions :: LSP. Options
8884 , argsDefaultHlsConfig :: Config
85+ , argsGetHieDbLoc :: FilePath -> IO FilePath -- ^ Map project roots to the location of the hiedb for the project
8986 }
9087
91- defArguments :: HieDb -> IndexQueue -> Arguments
92- defArguments hiedb hiechan =
88+ defArguments :: Arguments
89+ defArguments =
9390 Arguments
9491 { argsOTMemoryProfiling = False
9592 , argFiles = Nothing
9693 , argsLogger = noLogging
97- , argsHiedb = hiedb
98- , argsHieChan = hiechan
9994 , argsRules = mainRule >> action kick
10095 , argsGhcidePlugin = mempty
10196 , argsHlsPlugins = pluginDescToIdePlugins Ghcide. descriptors
10297 , argsSessionLoadingOptions = defaultLoadingOptions
10398 , argsIdeOptions = const defaultIdeOptions
10499 , argsLspOptions = def {LSP. completionTriggerCharacters = Just " ." }
105100 , argsDefaultHlsConfig = def
101+ , argsGetHieDbLoc = getHieDbLoc
106102 }
107103
108104defaultMain :: Arguments -> IO ()
109105defaultMain Arguments {.. } = do
110- dir <- IO. getCurrentDirectory
111106 pid <- T. pack . show <$> getProcessID
112107
113108 let hlsPlugin = asGhcIdePlugin argsHlsPlugins
@@ -121,10 +116,12 @@ defaultMain Arguments{..} = do
121116 t <- offsetTime
122117 hPutStrLn stderr " Starting LSP server..."
123118 hPutStrLn stderr " If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option!"
124- runLanguageServer options argsOnConfigChange (pluginHandlers plugins) $ \ env vfs rootPath -> do
119+ runLanguageServer options argsGetHieDbLoc argsOnConfigChange (pluginHandlers plugins) $ \ env vfs rootPath hiedb hieChan -> do
125120 t <- t
126121 hPutStrLn stderr $ " Started LSP server in " ++ showDuration t
127122
123+ dir <- IO. getCurrentDirectory
124+
128125 -- We want to set the global DynFlags right now, so that we can use
129126 -- `unsafeGlobalDynFlags` even before the project is configured
130127 -- We do it here since haskell-lsp changes our working directory to the correct place ('rootPath')
@@ -148,9 +145,12 @@ defaultMain Arguments{..} = do
148145 debouncer
149146 options
150147 vfs
151- argsHiedb
152- argsHieChan
148+ hiedb
149+ hieChan
153150 Just argFiles -> do
151+ dir <- IO. getCurrentDirectory
152+ dbLoc <- getHieDbLoc dir
153+ runWithDb dbLoc $ \ hiedb hieChan -> do
154154 -- GHC produces messages with UTF8 in them, so make sure the terminal doesn't error
155155 hSetEncoding stdout utf8
156156 hSetEncoding stderr utf8
@@ -178,7 +178,7 @@ defaultMain Arguments{..} = do
178178 { optCheckParents = pure NeverCheck
179179 , optCheckProject = pure False
180180 }
181- ide <- initialise mainRule Nothing argsLogger debouncer options vfs argsHiedb argsHieChan
181+ ide <- initialise mainRule Nothing argsLogger debouncer options vfs hiedb hieChan
182182
183183 putStrLn " \n Step 4/4: Type checking the files"
184184 setFilesOfInterest ide $ HashMap. fromList $ map ((,OnDisk ) . toNormalizedFilePath') files
0 commit comments