Skip to content

Commit 981f777

Browse files
fendorwz1000
authored andcommitted
Move plugin initialisation to 'GetModSummary' rule
1 parent 79368d4 commit 981f777

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,9 @@ getModSummaryFromImports env fp modTime contents = do
11511151
then mkHomeModLocation dflags (pathToModuleName fp) fp
11521152
else mkHomeModLocation dflags mod fp
11531153

1154-
let modl = mkHomeModule (hscHomeUnit (hscSetFlags dflags env)) mod
1154+
let modl = mkHomeModule (hscHomeUnit env) mod
11551155
sourceType = if "-boot" `isSuffixOf` takeExtension fp then HsBootFile else HsSrcFile
1156-
msrModSummary =
1156+
msrModSummary2 =
11571157
ModSummary
11581158
{ ms_mod = modl
11591159
, ms_hie_date = Nothing
@@ -1178,7 +1178,8 @@ getModSummaryFromImports env fp modTime contents = do
11781178
, ms_textual_imps = textualImports
11791179
}
11801180

1181-
msrFingerprint <- liftIO $ computeFingerprint opts msrModSummary
1181+
msrFingerprint <- liftIO $ computeFingerprint opts msrModSummary2
1182+
(msrModSummary, msrHscEnv) <- liftIO $ initPlugins env msrModSummary2
11821183
return ModSummaryResult{..}
11831184
where
11841185
-- Compute a fingerprint from the contents of `ModSummary`,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ data ModSummaryResult = ModSummaryResult
357357
{ msrModSummary :: !ModSummary
358358
, msrImports :: [LImportDecl GhcPs]
359359
, msrFingerprint :: !Fingerprint
360+
, msrHscEnv :: !HscEnv
361+
-- ^ HscEnv for this particular ModSummary.
362+
-- Contains initialised plugins, parsed options, etc...
363+
--
364+
-- Implicit assumption: DynFlags in 'msrModSummary' are the same as
365+
-- the DynFlags in 'msrHscEnv'.
360366
}
361367

362368
instance Show ModSummaryResult where

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ getParsedModuleRule :: Recorder (WithPriority Log) -> Rules ()
253253
getParsedModuleRule recorder =
254254
-- this rule does not have early cutoff since all its dependencies already have it
255255
define (cmapWithPrio LogShake recorder) $ \GetParsedModule file -> do
256-
ModSummaryResult{msrModSummary = ms'} <- use_ GetModSummary file
257-
sess <- use_ GhcSession file
258-
(ms', hsc) <- liftIO $ initPlugins (hscEnv sess) ms'
256+
ModSummaryResult{msrModSummary = ms', msrHscEnv = hsc} <- use_ GetModSummary file
259257
opt <- getIdeOptions
260258
modify_dflags <- getModifyDynFlags dynFlagsModifyParser
261259
let ms = ms' { ms_hspp_opts = modify_dflags $ ms_hspp_opts ms' }
@@ -327,9 +325,7 @@ getParsedModuleWithCommentsRule recorder =
327325
-- The parse diagnostics are owned by the GetParsedModule rule
328326
-- For this reason, this rule does not produce any diagnostics
329327
defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \GetParsedModuleWithComments file -> do
330-
ModSummaryResult{msrModSummary = ms} <- use_ GetModSummary file
331-
sess <- use_ GhcSession file
332-
(ms, hsc) <- liftIO $ initPlugins (hscEnv sess) ms
328+
ModSummaryResult{msrModSummary = ms, msrHscEnv = hsc} <- use_ GetModSummary file
333329
opt <- getIdeOptions
334330

335331
let ms' = withoutOption Opt_Haddock $ withOption Opt_KeepRawTokenStream ms

0 commit comments

Comments
 (0)