@@ -12,7 +12,7 @@ module Development.IDE.Main
1212) where
1313
1414import Control.Concurrent.Extra (withNumCapabilities )
15- import Control.Concurrent.MVar (newEmptyMVar ,
15+ import Control.Concurrent.MVar (MVar , newEmptyMVar ,
1616 putMVar , tryReadMVar )
1717import Control.Concurrent.STM.Stats (dumpSTMStats )
1818import 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