Skip to content

Commit 2ea1046

Browse files
committed
[fix] don't bake ide state mvar into setup and getIdeState
This is the right thing to do because othewise it is not possible to create new ideStates in a single instance of the executable. This will be useful if the hls executable is supposed to talk to multiple clients and lives beyond a single client disconnecting.
1 parent b8c9b84 commit 2ea1046

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ghcide/src/Development/IDE/Main.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Development.IDE.Main
1212
) where
1313

1414
import Control.Concurrent.Extra (withNumCapabilities)
15-
import Control.Concurrent.MVar (newEmptyMVar,
15+
import Control.Concurrent.MVar (MVar, newEmptyMVar,
1616
putMVar, tryReadMVar)
1717
import Control.Concurrent.STM.Stats (dumpSTMStats)
1818
import Control.Monad.Extra (concatMapM, unless,
@@ -318,9 +318,8 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
318318
ioT <- offsetTime
319319
logWith recorder Info $ LogLspStart (pluginId <$> ipMap argsHlsPlugins)
320320

321-
ideStateVar <- newEmptyMVar
322-
let getIdeState :: LSP.LanguageContextEnv Config -> FilePath -> WithHieDb -> Shake.ThreadQueue -> IO IdeState
323-
getIdeState env rootPath withHieDb threadQueue = do
321+
let getIdeState :: MVar IdeState -> LSP.LanguageContextEnv Config -> FilePath -> WithHieDb -> Shake.ThreadQueue -> IO IdeState
322+
getIdeState ideStateVar env rootPath withHieDb threadQueue = do
324323
t <- ioT
325324
logWith recorder Info $ LogLspStartDuration t
326325
sessionLoader <- loadSessionWithOptions (cmapWithPrio LogSession recorder) argsSessionLoadingOptions rootPath (tLoaderQueue threadQueue)
@@ -353,9 +352,9 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
353352
putMVar ideStateVar ide
354353
pure ide
355354

356-
let setup = setupLSP (cmapWithPrio LogLanguageServer recorder) argsProjectRoot argsGetHieDbLoc (pluginHandlers plugins) getIdeState
355+
let setup ideStateVar = setupLSP (cmapWithPrio LogLanguageServer recorder) argsProjectRoot argsGetHieDbLoc (pluginHandlers plugins) (getIdeState ideStateVar)
357356
-- See Note [Client configuration in Rules]
358-
onConfigChange cfg = do
357+
onConfigChange ideStateVar cfg = do
359358
-- TODO: this is nuts, we're converting back to JSON just to get a fingerprint
360359
let cfgObj = J.toJSON cfg
361360
mide <- liftIO $ tryReadMVar ideStateVar
@@ -368,7 +367,9 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
368367
modifyClientSettings ide (const $ Just cfgObj)
369368
return [toNoFileKey Rules.GetClientSettings]
370369

371-
runLanguageServer (cmapWithPrio LogLanguageServer recorder) options inH outH argsDefaultHlsConfig argsParseConfig onConfigChange setup
370+
do
371+
ideStateVar <- newEmptyMVar
372+
runLanguageServer (cmapWithPrio LogLanguageServer recorder) options inH outH argsDefaultHlsConfig argsParseConfig (onConfigChange ideStateVar) (setup ideStateVar)
372373
dumpSTMStats
373374
Check argFiles -> do
374375
let dir = argsProjectRoot

0 commit comments

Comments
 (0)