Skip to content
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

Don't use typecheck rule for non FOIs in refine imports plugin #2995

Merged
merged 1 commit into from
Jul 21, 2022
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
15 changes: 15 additions & 0 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ data Log
| LogLoadingHieFileFail !FilePath !SomeException
| LogLoadingHieFileSuccess !FilePath
| LogExactPrint ExactPrint.Log
| LogTypecheckedFOI !NormalizedFilePath
deriving Show

instance Pretty Log where
Expand All @@ -182,6 +183,14 @@ instance Pretty Log where
LogLoadingHieFileSuccess path ->
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
LogExactPrint log -> pretty log
LogTypecheckedFOI path -> vcat
[ "WARNING: Typechecked a file which is not currently open in the editor:" <+> pretty (fromNormalizedFilePath path)
wz1000 marked this conversation as resolved.
Show resolved Hide resolved
, "This can indicate a bug which results in excessive memory usage."
, "This may be a spurious warning if you have recently closed the file."
, "If you haven't opened this file recently, please file a report on the issue tracker mentioning"
<+> "the HLS version being used, the plugins enabled, and if possible the codebase and file which"
<+> "triggered this warning."
]

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

knownFilesRule :: Recorder (WithPriority Log) -> Rules ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm
-- second layer is from the imports of first layer to their imports
ImportMap importIm <- use_ GetImportMap path
forM importIm $ \imp_path -> do
imp_tmr <- use_ TypeCheck imp_path
return $ tcg_exports $ tmrTypechecked imp_tmr
imp_hir <- use_ GetModIface imp_path
return $ mi_exports $ hirModIface imp_hir

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