Skip to content

Commit

Permalink
Allow GHC plugins to be called with an updated StringBuffer (haskell/…
Browse files Browse the repository at this point in the history
…ghcide#698)

* Ignore tags file

* Pass an updated StringBuffer in ModSummary construction

The `getModSummaryFromBuffer` function constructs a `ModSummary` that
will be included in the `ParsedModule` data structure ghcide will later
on typecheck, calling any registred plugin in the process.

There was a problem, though: such `ModSummary` didn't include the
updated `StringBuffer` representing the in-memory content of a file
being edited (inclusive of all its unsaved changes). This was causing
plugins to not react in real time and emitting diagnostics only upon
save.

This commit fixes it.
  • Loading branch information
adinapoli authored Jul 20, 2020
1 parent 089edcd commit 0a4ef81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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 @@ -411,8 +411,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 @@ -428,7 +429,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 @@ -565,7 +572,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

0 comments on commit 0a4ef81

Please sign in to comment.