@@ -13,12 +13,16 @@ module Development.IDE.Main
1313) where
1414
1515import Control.Concurrent.Extra (withNumCapabilities )
16+ import Control.Concurrent.MVar (newEmptyMVar ,
17+ putMVar , tryReadMVar )
1618import Control.Concurrent.STM.Stats (dumpSTMStats )
1719import Control.Exception.Safe (SomeException ,
1820 catchAny ,
1921 displayException )
2022import Control.Monad.Extra (concatMapM , unless ,
2123 when )
24+ import Control.Monad.IO.Class (liftIO )
25+ import qualified Data.Aeson as J
2226import Data.Coerce (coerce )
2327import Data.Default (Default (def ))
2428import Data.Foldable (traverse_ )
@@ -31,11 +35,14 @@ import Data.Maybe (catMaybes, isJust)
3135import qualified Data.Text as T
3236import Development.IDE (Action ,
3337 Priority (Debug , Error ),
34- Rules , hDuplicateTo' )
38+ Rules , emptyFilePath ,
39+ hDuplicateTo' )
3540import Development.IDE.Core.Debouncer (Debouncer ,
3641 newAsyncDebouncer )
37- import Development.IDE.Core.FileStore (isWatchSupported )
42+ import Development.IDE.Core.FileStore (isWatchSupported ,
43+ setSomethingModified )
3844import Development.IDE.Core.IdeConfiguration (IdeConfiguration (.. ),
45+ modifyClientSettings ,
3946 registerIdeConfiguration )
4047import Development.IDE.Core.OfInterest (FileOfInterestStatus (OnDisk ),
4148 kick ,
@@ -83,7 +90,7 @@ import Development.IDE.Types.Options (IdeGhcSession,
8390 defaultIdeOptions ,
8491 optModifyDynFlags ,
8592 optTesting )
86- import Development.IDE.Types.Shake (WithHieDb )
93+ import Development.IDE.Types.Shake (WithHieDb , toKey )
8794import GHC.Conc (getNumProcessors )
8895import GHC.IO.Encoding (setLocaleEncoding )
8996import GHC.IO.Handle (hDuplicate )
@@ -95,8 +102,8 @@ import Ide.Logger (Logger,
95102 Recorder ,
96103 WithPriority ,
97104 cmapWithPrio ,
98- logWith , nest , vsep ,
99- (<+>) )
105+ logDebug , logWith ,
106+ nest , vsep , (<+>) )
100107import Ide.Plugin.Config (CheckParents (NeverCheck ),
101108 Config , checkParents ,
102109 checkProject ,
@@ -289,7 +296,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
289296 hlsCommands = allLspCmdIds' pid argsHlsPlugins
290297 plugins = hlsPlugin <> argsGhcidePlugin
291298 options = argsLspOptions { LSP. optExecuteCommandCommands = LSP. optExecuteCommandCommands argsLspOptions <> Just hlsCommands }
292- argsOnConfigChange = getConfigFromNotification argsHlsPlugins
299+ argsParseConfig = getConfigFromNotification argsHlsPlugins
293300 rules = argsRules >> pluginRules plugins
294301
295302 debouncer <- argsDebouncer
@@ -304,6 +311,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
304311 ioT <- offsetTime
305312 logWith recorder Info $ LogLspStart (pluginId <$> ipMap argsHlsPlugins)
306313
314+ ideStateVar <- newEmptyMVar
307315 let getIdeState :: LSP. LanguageContextEnv Config -> Maybe FilePath -> WithHieDb -> IndexQueue -> IO IdeState
308316 getIdeState env rootPath withHieDb hieChan = do
309317 traverse_ IO. setCurrentDirectory rootPath
@@ -334,7 +342,7 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
334342 }
335343 caps = LSP. resClientCapabilities env
336344 monitoring <- argsMonitoring
337- initialise
345+ ide <- initialise
338346 (cmapWithPrio LogService recorder)
339347 argsDefaultHlsConfig
340348 argsHlsPlugins
@@ -346,10 +354,24 @@ defaultMain recorder Arguments{..} = withHeapStats (cmapWithPrio LogHeapStats re
346354 withHieDb
347355 hieChan
348356 monitoring
357+ putMVar ideStateVar ide
358+ pure ide
349359
350360 let setup = setupLSP (cmapWithPrio LogLanguageServer recorder) argsGetHieDbLoc (pluginHandlers plugins) getIdeState
351-
352- runLanguageServer (cmapWithPrio LogLanguageServer recorder) options inH outH argsDefaultHlsConfig argsOnConfigChange setup
361+ -- See Note [Client configuration in Rules]
362+ onConfigChange cfg = do
363+ -- TODO: this is nuts, we're converting back to JSON just to get a fingerprint
364+ let cfgObj = J. toJSON cfg
365+ mide <- liftIO $ tryReadMVar ideStateVar
366+ case mide of
367+ Nothing -> pure ()
368+ Just ide -> liftIO $ do
369+ let msg = T. pack $ show cfg
370+ logDebug (Shake. ideLogger ide) $ " Configuration changed: " <> msg
371+ modifyClientSettings ide (const $ Just cfgObj)
372+ setSomethingModified Shake. VFSUnmodified ide [toKey Rules. GetClientSettings emptyFilePath] " config change"
373+
374+ runLanguageServer (cmapWithPrio LogLanguageServer recorder) options inH outH argsDefaultHlsConfig argsParseConfig onConfigChange setup
353375 dumpSTMStats
354376 Check argFiles -> do
355377 dir <- maybe IO. getCurrentDirectory return argsProjectRoot
0 commit comments