@@ -78,7 +78,8 @@ import Ide.Logger (Pretty (pretty),
78
78
nest ,
79
79
toCologActionWithPrio ,
80
80
vcat , viaShow , (<+>) )
81
- import Ide.Types (SessionLoadingPreferenceConfig (.. ),
81
+ import Ide.Types (Config ,
82
+ SessionLoadingPreferenceConfig (.. ),
82
83
sessionLoading )
83
84
import Language.LSP.Protocol.Message
84
85
import Language.LSP.Server
@@ -460,7 +461,8 @@ data SessionState = SessionState
460
461
hscEnvs :: ! (Var HieMap ),
461
462
fileToFlags :: ! FlagsMap ,
462
463
filesMap :: ! FilesMap ,
463
- version :: ! (Var Int )
464
+ version :: ! (Var Int ),
465
+ sessionLoadingPreferenceConfig :: ! (Var (Maybe SessionLoadingPreferenceConfig ))
464
466
}
465
467
466
468
-- | Helper functions for SessionState management
@@ -570,6 +572,24 @@ getExtraFilesToLoad state cfp = do
570
572
-- remove error files from pending files since error loading need to load one by one
571
573
else (Set. delete cfp $ pendingFiles `Set.difference` errorFiles) <> old_files
572
574
575
+ -- | We allow users to specify a loading strategy.
576
+ -- Check whether this config was changed since the last time we have loaded
577
+ -- a session.
578
+ --
579
+ -- If the loading configuration changed, we likely should restart the session
580
+ -- in its entirety.
581
+ didSessionLoadingPreferenceConfigChange :: SessionState -> Config -> IO Bool
582
+ didSessionLoadingPreferenceConfigChange s clientConfig = do
583
+ let biosSessionLoadingVar = sessionLoadingPreferenceConfig s
584
+ mLoadingConfig <- readVar biosSessionLoadingVar
585
+ case mLoadingConfig of
586
+ Nothing -> do
587
+ writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
588
+ pure False
589
+ Just loadingConfig -> do
590
+ writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
591
+ pure (loadingConfig /= sessionLoading clientConfig)
592
+
573
593
newSessionState :: IO SessionState
574
594
newSessionState = do
575
595
-- Initialize SessionState
@@ -581,6 +601,7 @@ newSessionState = do
581
601
<*> STM. newIO -- fileToFlags
582
602
<*> STM. newIO -- filesMap
583
603
<*> newVar 0 -- version
604
+ <*> newVar Nothing -- sessionLoadingPreferenceConfig
584
605
return sessionState
585
606
586
607
-- | Given a root directory, return a Shake 'Action' which setups an
@@ -602,7 +623,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
602
623
let toAbsolutePath = toAbsolute rootDir -- see Note [Root Directory]
603
624
604
625
sessionState <- newSessionState
605
- biosSessionLoadingVar <- newVar Nothing :: IO (Var (Maybe SessionLoadingPreferenceConfig ))
606
626
let returnWithVersion fun = IdeGhcSession fun <$> liftIO (readVar (version sessionState))
607
627
608
628
-- This caches the mapping from Mod.hs -> hie.yaml
@@ -833,31 +853,12 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
833
853
-- we are only loading this file and it failed
834
854
let res = map (\ err' -> renderCradleError err' cradle ncfp) err
835
855
handleFileProcessingError sessionState hieYaml cfp res $ concatMap cradleErrorDependencies err
836
-
837
- let
838
- -- | We allow users to specify a loading strategy.
839
- -- Check whether this config was changed since the last time we have loaded
840
- -- a session.
841
- --
842
- -- If the loading configuration changed, we likely should restart the session
843
- -- in its entirety.
844
- didSessionLoadingPreferenceConfigChange :: IO Bool
845
- didSessionLoadingPreferenceConfigChange = do
846
- mLoadingConfig <- readVar biosSessionLoadingVar
847
- case mLoadingConfig of
848
- Nothing -> do
849
- writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
850
- pure False
851
- Just loadingConfig -> do
852
- writeVar biosSessionLoadingVar (Just (sessionLoading clientConfig))
853
- pure (loadingConfig /= sessionLoading clientConfig)
854
-
855
856
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
856
857
-- Returns the Ghc session and the cradle dependencies
857
858
let sessionOpts :: (Maybe FilePath , FilePath )
858
859
-> IO ()
859
860
sessionOpts (hieYaml, file) = do
860
- Extra. whenM didSessionLoadingPreferenceConfigChange $ do
861
+ Extra. whenM ( didSessionLoadingPreferenceConfigChange sessionState clientConfig) $ do
861
862
logWith recorder Info LogSessionLoadingChanged
862
863
-- If the dependencies are out of date then clear both caches and start
863
864
-- again.
0 commit comments