@@ -165,6 +165,7 @@ data Log
165165 | LogLoadingHieFileFail ! FilePath ! SomeException
166166 | LogLoadingHieFileSuccess ! FilePath
167167 | LogExactPrint ExactPrint. Log
168+ | LogTypecheckedFOI ! NormalizedFilePath
168169 deriving Show
169170
170171instance 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
186195templateHaskellInstructions :: T. Text
187196templateHaskellInstructions = " https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries"
@@ -650,6 +659,12 @@ typeCheckRule :: Recorder (WithPriority Log) -> Rules ()
650659typeCheckRule 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
655670knownFilesRule :: Recorder (WithPriority Log ) -> Rules ()
0 commit comments