Skip to content

Commit c045857

Browse files
committed
Don't use typecheck rule for non FOIs in refine imports plugin
Also add an assertion to check that we never use non-FOI rules Fixes #2962
1 parent 100b53a commit c045857

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ data Log
165165
| LogLoadingHieFileFail !FilePath !SomeException
166166
| LogLoadingHieFileSuccess !FilePath
167167
| LogExactPrint ExactPrint.Log
168+
| LogTypecheckedFOI !NormalizedFilePath
168169
deriving Show
169170

170171
instance Pretty Log where
@@ -182,6 +183,14 @@ instance Pretty Log where
182183
LogLoadingHieFileSuccess path ->
183184
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
184185
LogExactPrint log -> pretty log
186+
LogTypecheckedFOI path -> vcat
187+
[ "WARNING: Typechecked a file which is not currently open in the editor:" <+> pretty (fromNormalizedFilePath path)
188+
, "This can indicate a bug which results in excessive memory usage."
189+
, "This may be a spurious warning if you have recently closed the file."
190+
, "If you haven't opened this file recently, please file a report on the issue tracker mentioning"
191+
<+> "the HLS version being used, the plugins enabled, and if possible the codebase and file which"
192+
<+> "triggered this warning."
193+
]
185194

186195
templateHaskellInstructions :: T.Text
187196
templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries"
@@ -650,6 +659,12 @@ typeCheckRule :: Recorder (WithPriority Log) -> Rules ()
650659
typeCheckRule recorder = define (cmapWithPrio LogShake recorder) $ \TypeCheck file -> do
651660
pm <- use_ GetParsedModule file
652661
hsc <- hscEnv <$> use_ GhcSessionDeps file
662+
foi <- use_ IsFileOfInterest file
663+
-- We should only call the typecheck rule for files of interest.
664+
-- Keeping typechecked modules in memory for other files is
665+
-- very expensive.
666+
when (foi == NotFOI) $
667+
logWith recorder Logger.Warning $ LogTypecheckedFOI file
653668
typeCheckRuleDefinition hsc pm
654669

655670
knownFilesRule :: Recorder (WithPriority Log) -> Rules ()

plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm
187187
-- second layer is from the imports of first layer to their imports
188188
ImportMap importIm <- use_ GetImportMap path
189189
forM importIm $ \imp_path -> do
190-
imp_tmr <- use_ TypeCheck imp_path
191-
return $ tcg_exports $ tmrTypechecked imp_tmr
190+
imp_hir <- use_ GetModIface imp_path
191+
return $ mi_exports $ hirModIface imp_hir
192192

193193
-- Use the GHC api to extract the "minimal" imports
194194
-- We shouldn't blindly refine imports

0 commit comments

Comments
 (0)