Skip to content

Commit 1976ea2

Browse files
authored
Delay the Shake session setup until the Initialized handler (#1754)
* remove unused field * Delay Shake session start * fix Check and Custom commands
1 parent 6949b15 commit 1976ea2

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
-- always stored as real Haskell values, whereas Shake serialises all 'A' values
2424
-- between runs. To deserialise a Shake value, we just consult Values.
2525
module Development.IDE.Core.Shake(
26-
IdeState, shakeExtras,
26+
IdeState, shakeSessionInit, shakeExtras,
2727
ShakeExtras(..), getShakeExtras, getShakeExtrasRules,
2828
KnownTargets, Target(..), toKnownFiles,
2929
IdeRule, IdeResult,
@@ -32,6 +32,7 @@ module Development.IDE.Core.Shake(
3232
shakeRestart,
3333
shakeEnqueue,
3434
shakeProfile,
35+
newSession,
3536
use, useNoFile, uses, useWithStaleFast, useWithStaleFast', delayedAction,
3637
FastResult(..),
3738
use_, useNoFile_, uses_,
@@ -110,6 +111,11 @@ import Development.IDE.Core.Tracing
110111
import Development.IDE.GHC.Compat (NameCacheUpdater (..),
111112
upNameCache)
112113
import Development.IDE.GHC.Orphans ()
114+
import Development.IDE.Graph hiding (ShakeValue)
115+
import qualified Development.IDE.Graph as Shake
116+
import Development.IDE.Graph.Classes
117+
import Development.IDE.Graph.Database
118+
import Development.IDE.Graph.Rule
113119
import Development.IDE.Types.Action
114120
import Development.IDE.Types.Diagnostics
115121
import Development.IDE.Types.Exports
@@ -119,11 +125,6 @@ import Development.IDE.Types.Logger hiding (Priority)
119125
import qualified Development.IDE.Types.Logger as Logger
120126
import Development.IDE.Types.Options
121127
import Development.IDE.Types.Shake
122-
import Development.IDE.Graph hiding (ShakeValue)
123-
import qualified Development.IDE.Graph as Shake
124-
import Development.IDE.Graph.Classes
125-
import Development.IDE.Graph.Database
126-
import Development.IDE.Graph.Rule
127128
import GHC.Generics
128129
import Language.LSP.Diagnostics
129130
import qualified Language.LSP.Server as LSP
@@ -187,8 +188,6 @@ data ShakeExtras = ShakeExtras
187188
,progressUpdate :: ProgressEvent -> IO ()
188189
,ideTesting :: IdeTesting
189190
-- ^ Whether to enable additional lsp messages used by the test suite for checking invariants
190-
,session :: MVar ShakeSession
191-
-- ^ Used in the GhcSession rule to forcefully restart the session after adding a new component
192191
,restartShakeSession :: [DelayedAction ()] -> IO ()
193192
,ideNc :: IORef NameCache
194193
-- | A mapping of module name to known target (or candidate targets, if missing)
@@ -488,7 +487,6 @@ shakeOpen lspEnv defaultConfig logger debouncer
488487
positionMapping <- newVar HMap.empty
489488
knownTargetsVar <- newVar $ hashed HMap.empty
490489
let restartShakeSession = shakeRestart ideState
491-
let session = shakeSession
492490
mostRecentProgressEvent <- newTVarIO KickCompleted
493491
persistentKeys <- newVar HMap.empty
494492
let progressUpdate = atomically . writeTVar mostRecentProgressEvent
@@ -511,8 +509,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
511509
opts { shakeExtra = newShakeExtra shakeExtras }
512510
rules
513511
shakeDb <- shakeDbM
514-
initSession <- newSession shakeExtras shakeDb []
515-
shakeSession <- newMVar initSession
512+
shakeSession <- newEmptyMVar
516513
shakeDatabaseProfile <- shakeDatabaseProfileIO shakeProfileDir
517514
let ideState = IdeState{..}
518515

@@ -611,6 +608,12 @@ shakeOpen lspEnv defaultConfig logger debouncer
611608
}
612609
loop id next
613610

611+
-- | Must be called in the 'Initialized' handler and only once
612+
shakeSessionInit :: IdeState -> IO ()
613+
shakeSessionInit IdeState{..} = do
614+
initSession <- newSession shakeExtras shakeDb []
615+
putMVar shakeSession initSession
616+
614617
shakeProfile :: IdeState -> FilePath -> IO ()
615618
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb
616619

ghcide/src/Development/IDE/LSP/Notifications.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
104104
setSomethingModified ide
105105

106106
, mkPluginNotificationHandler LSP.SInitialized $ \ide _ _ -> do
107+
--------- Initialize Shake session --------------------------------------------------------------------
108+
liftIO $ shakeSessionInit ide
109+
110+
--------- Set up file watchers ------------------------------------------------------------------------
107111
clientCapabilities <- LSP.getClientCapabilities
108112
let watchSupported = case () of
109113
_ | LSP.ClientCapabilities{_workspace} <- clientCapabilities

ghcide/src/Development/IDE/Main.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ import Development.IDE.Core.Rules (GhcSessionIO (GhcSession
4242
import Development.IDE.Core.Service (initialise, runAction)
4343
import Development.IDE.Core.Shake (IdeState (shakeExtras),
4444
ShakeExtras (state),
45-
uses)
45+
shakeSessionInit, uses)
4646
import Development.IDE.Core.Tracing (measureMemory)
47+
import Development.IDE.Graph (action)
4748
import Development.IDE.LSP.LanguageServer (runLanguageServer)
4849
import Development.IDE.Plugin (Plugin (pluginHandlers, pluginRules))
4950
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
@@ -61,7 +62,6 @@ import Development.IDE.Types.Options (IdeGhcSession,
6162
clientSupportsProgress,
6263
defaultIdeOptions)
6364
import Development.IDE.Types.Shake (Key (Key))
64-
import Development.IDE.Graph (action)
6565
import GHC.IO.Encoding (setLocaleEncoding)
6666
import GHC.IO.Handle (hDuplicate)
6767
import HIE.Bios.Cradle (findCradle)
@@ -261,6 +261,7 @@ defaultMain Arguments{..} = do
261261
, optCheckProject = pure False
262262
}
263263
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
264+
shakeSessionInit ide
264265
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
265266

266267
putStrLn "\nStep 4/4: Type checking the files"
@@ -309,6 +310,7 @@ defaultMain Arguments{..} = do
309310
optCheckProject = pure False
310311
}
311312
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
313+
shakeSessionInit ide
312314
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
313315
c ide
314316

0 commit comments

Comments
 (0)