Skip to content

Delay the Shake session setup until the Initialized handler #1754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
-- always stored as real Haskell values, whereas Shake serialises all 'A' values
-- between runs. To deserialise a Shake value, we just consult Values.
module Development.IDE.Core.Shake(
IdeState, shakeExtras,
IdeState, shakeSessionInit, shakeExtras,
ShakeExtras(..), getShakeExtras, getShakeExtrasRules,
KnownTargets, Target(..), toKnownFiles,
IdeRule, IdeResult,
Expand All @@ -32,6 +32,7 @@ module Development.IDE.Core.Shake(
shakeRestart,
shakeEnqueue,
shakeProfile,
newSession,
use, useNoFile, uses, useWithStaleFast, useWithStaleFast', delayedAction,
FastResult(..),
use_, useNoFile_, uses_,
Expand Down Expand Up @@ -110,6 +111,11 @@ import Development.IDE.Core.Tracing
import Development.IDE.GHC.Compat (NameCacheUpdater (..),
upNameCache)
import Development.IDE.GHC.Orphans ()
import Development.IDE.Graph hiding (ShakeValue)
import qualified Development.IDE.Graph as Shake
import Development.IDE.Graph.Classes
import Development.IDE.Graph.Database
import Development.IDE.Graph.Rule
import Development.IDE.Types.Action
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Exports
Expand All @@ -119,11 +125,6 @@ import Development.IDE.Types.Logger hiding (Priority)
import qualified Development.IDE.Types.Logger as Logger
import Development.IDE.Types.Options
import Development.IDE.Types.Shake
import Development.IDE.Graph hiding (ShakeValue)
import qualified Development.IDE.Graph as Shake
import Development.IDE.Graph.Classes
import Development.IDE.Graph.Database
import Development.IDE.Graph.Rule
import GHC.Generics
import Language.LSP.Diagnostics
import qualified Language.LSP.Server as LSP
Expand Down Expand Up @@ -187,8 +188,6 @@ data ShakeExtras = ShakeExtras
,progressUpdate :: ProgressEvent -> IO ()
,ideTesting :: IdeTesting
-- ^ Whether to enable additional lsp messages used by the test suite for checking invariants
,session :: MVar ShakeSession
-- ^ Used in the GhcSession rule to forcefully restart the session after adding a new component
,restartShakeSession :: [DelayedAction ()] -> IO ()
,ideNc :: IORef NameCache
-- | A mapping of module name to known target (or candidate targets, if missing)
Expand Down Expand Up @@ -488,7 +487,6 @@ shakeOpen lspEnv defaultConfig logger debouncer
positionMapping <- newVar HMap.empty
knownTargetsVar <- newVar $ hashed HMap.empty
let restartShakeSession = shakeRestart ideState
let session = shakeSession
mostRecentProgressEvent <- newTVarIO KickCompleted
persistentKeys <- newVar HMap.empty
let progressUpdate = atomically . writeTVar mostRecentProgressEvent
Expand All @@ -511,8 +509,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
opts { shakeExtra = newShakeExtra shakeExtras }
rules
shakeDb <- shakeDbM
initSession <- newSession shakeExtras shakeDb []
shakeSession <- newMVar initSession
shakeSession <- newEmptyMVar
shakeDatabaseProfile <- shakeDatabaseProfileIO shakeProfileDir
let ideState = IdeState{..}

Expand Down Expand Up @@ -611,6 +608,12 @@ shakeOpen lspEnv defaultConfig logger debouncer
}
loop id next

-- | Must be called in the 'Initialized' handler and only once
shakeSessionInit :: IdeState -> IO ()
shakeSessionInit IdeState{..} = do
initSession <- newSession shakeExtras shakeDb []
putMVar shakeSession initSession

shakeProfile :: IdeState -> FilePath -> IO ()
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb

Expand Down
4 changes: 4 additions & 0 deletions ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginNotificationHandlers =
setSomethingModified ide

, mkPluginNotificationHandler LSP.SInitialized $ \ide _ _ -> do
--------- Initialize Shake session --------------------------------------------------------------------
liftIO $ shakeSessionInit ide

--------- Set up file watchers ------------------------------------------------------------------------
clientCapabilities <- LSP.getClientCapabilities
let watchSupported = case () of
_ | LSP.ClientCapabilities{_workspace} <- clientCapabilities
Expand Down
6 changes: 4 additions & 2 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ import Development.IDE.Core.Rules (GhcSessionIO (GhcSession
import Development.IDE.Core.Service (initialise, runAction)
import Development.IDE.Core.Shake (IdeState (shakeExtras),
ShakeExtras (state),
uses)
shakeSessionInit, uses)
import Development.IDE.Core.Tracing (measureMemory)
import Development.IDE.Graph (action)
import Development.IDE.LSP.LanguageServer (runLanguageServer)
import Development.IDE.Plugin (Plugin (pluginHandlers, pluginRules))
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
Expand All @@ -61,7 +62,6 @@ import Development.IDE.Types.Options (IdeGhcSession,
clientSupportsProgress,
defaultIdeOptions)
import Development.IDE.Types.Shake (Key (Key))
import Development.IDE.Graph (action)
import GHC.IO.Encoding (setLocaleEncoding)
import GHC.IO.Handle (hDuplicate)
import HIE.Bios.Cradle (findCradle)
Expand Down Expand Up @@ -261,6 +261,7 @@ defaultMain Arguments{..} = do
, optCheckProject = pure False
}
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
shakeSessionInit ide
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)

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

Expand Down