Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Allow GHC plugins to be called with an updated StringBuffer #698

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ bench-temp/
.shake/
ghcide
*.benchmark-gcStats
tags
13 changes: 10 additions & 3 deletions src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,9 @@ getModSummaryFromBuffer
=> FilePath
-> DynFlags
-> GHC.ParsedSource
-> StringBuffer
-> ExceptT [FileDiagnostic] m ModSummary
getModSummaryFromBuffer fp dflags parsed = do
getModSummaryFromBuffer fp dflags parsed contents = do
(modName, imports) <- liftEither $ getImportsParsed dflags parsed

modLoc <- liftIO $ mkHomeModLocation dflags modName fp
Expand All @@ -424,7 +425,13 @@ getModSummaryFromBuffer fp dflags parsed = do
, ms_textual_imps = [imp | (False, imp) <- imports]
, ms_hspp_file = fp
, ms_hspp_opts = dflags
, ms_hspp_buf = Nothing
-- NOTE: It's /vital/ we set the 'StringBuffer' here, to give any
-- registered GHC plugins access to the /updated/ in-memory content
-- of a module being edited. Without this line, any plugin wishing to
-- parse an input module and perform operations on the /current/ state
-- of a file wouldn't work properly, as it would \"see\" a stale view of
-- the file (i.e., the on-disk content of the latter).
, ms_hspp_buf = Just contents

-- defaults:
, ms_hsc_src = sourceType
Expand Down Expand Up @@ -561,7 +568,7 @@ parseFileContents customPreprocessor dflags comp_pkgs filename contents = do
unless (null errs) $ throwE $ diagFromStrings "parser" DsError errs
let parsed' = removePackageImports comp_pkgs parsed
let preproc_warnings = diagFromStrings "parser" DsWarning preproc_warns
ms <- getModSummaryFromBuffer filename dflags parsed'
ms <- getModSummaryFromBuffer filename dflags parsed' contents
let pm =
ParsedModule {
pm_mod_summary = ms
Expand Down