Skip to content

Commit 4b6e691

Browse files
authored
Allow GHC plugins to be called with an updated StringBuffer (#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.
1 parent 0f06d30 commit 4b6e691

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ bench-temp/
1313
.shake/
1414
ghcide
1515
*.benchmark-gcStats
16+
tags

src/Development/IDE/Core/Compile.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,9 @@ getModSummaryFromBuffer
411411
=> FilePath
412412
-> DynFlags
413413
-> GHC.ParsedSource
414+
-> StringBuffer
414415
-> ExceptT [FileDiagnostic] m ModSummary
415-
getModSummaryFromBuffer fp dflags parsed = do
416+
getModSummaryFromBuffer fp dflags parsed contents = do
416417
(modName, imports) <- liftEither $ getImportsParsed dflags parsed
417418

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

433440
-- defaults:
434441
, ms_hsc_src = sourceType
@@ -565,7 +572,7 @@ parseFileContents customPreprocessor dflags comp_pkgs filename contents = do
565572
unless (null errs) $ throwE $ diagFromStrings "parser" DsError errs
566573
let parsed' = removePackageImports comp_pkgs parsed
567574
let preproc_warnings = diagFromStrings "parser" DsWarning preproc_warns
568-
ms <- getModSummaryFromBuffer filename dflags parsed'
575+
ms <- getModSummaryFromBuffer filename dflags parsed' contents
569576
let pm =
570577
ParsedModule {
571578
pm_mod_summary = ms

0 commit comments

Comments
 (0)