Skip to content

Commit

Permalink
Support structured diagnostics 2 (#4433)
Browse files Browse the repository at this point in the history
* Change FileDiagnostic type synonym to a datatype

* Make `ideErrorWithSource` produce FileDiagnostic by adding filepath arg

* Supply structured error wherever we easily can - TODOs for hard parts

We're leaving the TODOs for either later in this PR or in another PR

* Fix UnitTests for new FileDiagnostic struct

* Remove explicit uses of FileDiagnostic, add codes to LSP diagnostics

* Add field for expected error codes in ghcide tests

* Expect GHC-83865 for "type error" test - basic test

* Return structured warnings in TcModuleResult by copying from Driver

* Store FileDiagnostic instead of LSP Diagnostic in Shake store

* Add expected error codes for diagnostics that have them

* Dispatch TODOs, amend remaining TODOs as future work

* Add scary comments all over copied code in Compat.Driver

* Update all remaining diagnostics that could use an expected error code

* Add _code to pretty printing for FileDiagnostic

* Use case instead of `maybe` for StructuredMessage match

* Use CPP to prevent setting _code before structured errors

* Swap modifier for lenses, document StructuredMessage type

* Add link to Issue & MR to Compat.Driver

* Drop attachReason logic from withWarnings, technically incorrect

* Revert "Drop attachReason logic", needed by pragmas-plugin

This reverts commit 4fed987.

* Fix plugins where necessary for new diagnostic structure

* Fix build issues with other tests from `expectDiagnostics`

* Improve comment on metadata fdStructuredMessage in FileDiagnostic

* Add note to withWarnings explaining the current state of things

* Attach reasons into data field of LSP Diagnostic instead of code field

Had to move `attachReason` between modules to achieve this, which is
fine because it was never exported from its own module.

* Fix up mistakes from merge, TODO fix merge issues for 9.3.0

* Set CodeDescription from HaskellErrorIndex when available

* Remove debugging print, fix expectation for preprocessor tests

* Fix CPP for using Show instance on DiagnosticCode

* Remove diagFromErrMsgs for GHC version < 9.6.1 using CPP

* CPP fix

* More stylish-haskell, more CPP fix

* Fix all stylish-haskell errors triggering

* Fix more CPP

* Only override the LSP diagnostic code when not already set

* Fixes for stylish-haskell

stylish-haskell does not handle CPP pragmas very well, is this a
regression?

* Qualify s, t for FuzzySearch

* Ignore use of unsafePerformIO in FuzzySearch

* Properly split GHC.Types.Error import in Diagnostics for stylish-haskell

* Force type signature of annotation on FuzzySearch.dictionary

* DRY up definition of closure_errs

From review #4311 (comment)

* Remove unused imports

* Post-rebase fixes

* stylish-haskell formatting

* Fix issue with GHC 9.4

* Please stylish-haskell

* Ignore error codes when testing GHC 9.4

* Workaround darwin GHC bug in hls-hlint-plugin

* Put the workaround in the right place

* Revert "Set CodeDescription from HaskellErrorIndex when available"

This reverts commit 14d6697.

* Resolve fendor's feedback

* Apply stylish-haskell formatting

* Apply more stylish-haskell formatting

* Resolve some of soulomoon's feedback

* Fix small issues

* Remove unused imports

* Remove StructuredDiagnostic

* Revert "Remove StructuredDiagnostic"

This reverts commit 0776c65.

* Remove the unused parameter from 'ideErrorText'

* Add documentation to diagnostic helpers

* Add action to query active diagnostics for a given Range

Implement 'rangesOverlap' function which checks whether two 'Range's
overlap in any way.
Implement two new plugin utility functions which allow to conveniently
get all currently displayed diagnostics for a given 'Range'.

* Use lens for updating Diagnostic

* Add GHC Structured Error compatibility module

Add compatibility module for GHC's structured error messages.
Introduce 'Prism's and 'Lens's to easily access nested structures.
Expand documentation for 'StructuredMessage'

* Remove unused imports

* Don't suggest -Wno-deferred-out-of-scope-variables (#4441)

Fixes #4440

Fixes test for disabling deferred-type-errors.

* Build HLS with GHC 9.8.3 (#4444)

* ci(mergify): upgrade configuration to current format (#4454)

Co-authored-by: Mergify <37929162+mergify[bot]@users.noreply.github.com>

* More tests and better docs for cabal-add (#4455)

* new tests

* change codeAction title

* more tests and docs

---------

Co-authored-by: fendor <[email protected]>

* Fix compatibility with GHC 9.4 and rename function

* Use GHC Note syntax and reference Note in docs

Allows HLS to 'Goto Definition' for Note references.

* Add doc comment for 'tmrWarnings'

* Push CPP statements to compatibility module

* Fix formatting in Development.IDE.GHC.Compat.Error

---------

Co-authored-by: Dylan Thinnes <[email protected]>
Co-authored-by: soulomoon <[email protected]>
Co-authored-by: Fendor <[email protected]>
Co-authored-by: jeukshi <[email protected]>
Co-authored-by: fendor <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Georgii Gerasev <[email protected]>
  • Loading branch information
8 people authored Jan 4, 2025
1 parent f09500b commit b87bdb9
Show file tree
Hide file tree
Showing 46 changed files with 982 additions and 358 deletions.
2 changes: 1 addition & 1 deletion ghcide-bench/src/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ experiments =
flip allM docs $ \DocumentPositions{..} -> do
bottom <- pred . length . T.lines <$> documentContents doc
diags <- getCurrentDiagnostics doc
case requireDiagnostic diags (DiagnosticSeverity_Error, (fromIntegral bottom, 8), "Found hole", Nothing) of
case requireDiagnostic diags (DiagnosticSeverity_Error, (fromIntegral bottom, 8), "Found hole", Just "GHC-88464", Nothing) of
Nothing -> pure True
Just _err -> pure False
),
Expand Down
3 changes: 3 additions & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ library
, hls-plugin-api == 2.9.0.1
, implicit-hie >= 0.1.4.0 && < 0.1.5
, lens
, lens-aeson
, list-t
, lsp ^>=2.7
, lsp-types ^>=2.3
Expand Down Expand Up @@ -150,7 +151,9 @@ library
Development.IDE.GHC.Compat
Development.IDE.GHC.Compat.Core
Development.IDE.GHC.Compat.CmdLine
Development.IDE.GHC.Compat.Driver
Development.IDE.GHC.Compat.Env
Development.IDE.GHC.Compat.Error
Development.IDE.GHC.Compat.Iface
Development.IDE.GHC.Compat.Logger
Development.IDE.GHC.Compat.Outputable
Expand Down
34 changes: 22 additions & 12 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,11 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
this_flags = (this_error_env, this_dep_info)
this_error_env = ([this_error], Nothing)
this_error = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) _cfp
$ T.unlines
[ "No cradle target found. Is this file listed in the targets of your cradle?"
, "If you are using a .cabal file, please ensure that this module is listed in either the exposed-modules or other-modules section"
]
(T.unlines
[ "No cradle target found. Is this file listed in the targets of your cradle?"
, "If you are using a .cabal file, please ensure that this module is listed in either the exposed-modules or other-modules section"
])
Nothing

void $ modifyVar' fileToFlags $ Map.insert hieYaml this_flags_map
void $ modifyVar' filesMap $ flip HM.union (HM.fromList (map ((,hieYaml) . fst) $ concatMap toFlagsMap all_targets))
Expand Down Expand Up @@ -797,10 +798,10 @@ setNameCache nc hsc = hsc { hsc_NC = nc }
-- GHC had an implementation of this function, but it was horribly inefficient
-- We should move back to the GHC implementation on compilers where
-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12162 is included
checkHomeUnitsClosed' :: UnitEnv -> OS.Set UnitId -> [DriverMessages]
checkHomeUnitsClosed' :: UnitEnv -> OS.Set UnitId -> Maybe (Compat.MsgEnvelope DriverMessage)
checkHomeUnitsClosed' ue home_id_set
| OS.null bad_unit_ids = []
| otherwise = [singleMessage $ GHC.mkPlainErrorMsgEnvelope rootLoc $ DriverHomePackagesNotClosed (OS.toList bad_unit_ids)]
| OS.null bad_unit_ids = Nothing
| otherwise = Just (GHC.mkPlainErrorMsgEnvelope rootLoc $ DriverHomePackagesNotClosed (OS.toList bad_unit_ids))
where
bad_unit_ids = upwards_closure OS.\\ home_id_set
rootLoc = mkGeneralSrcSpan (Compat.fsLit "<command line>")
Expand Down Expand Up @@ -875,10 +876,19 @@ newComponentCache recorder exts _cfp hsc_env old_cis new_cis = do
hscEnv' <- -- Set up a multi component session with the other units on GHC 9.4
Compat.initUnits dfs hsc_env

let closure_errs = checkHomeUnitsClosed' (hsc_unit_env hscEnv') (hsc_all_home_unit_ids hscEnv')
multi_errs = map (ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Warning) _cfp . T.pack . Compat.printWithoutUniques) closure_errs
let closure_errs = maybeToList $ checkHomeUnitsClosed' (hsc_unit_env hscEnv') (hsc_all_home_unit_ids hscEnv')
closure_err_to_multi_err err =
ideErrorWithSource
(Just "cradle") (Just DiagnosticSeverity_Warning) _cfp
(T.pack (Compat.printWithoutUniques (singleMessage err)))
#if MIN_VERSION_ghc(9,5,0)
(Just (fmap GhcDriverMessage err))
#else
Nothing
#endif
multi_errs = map closure_err_to_multi_err closure_errs
bad_units = OS.fromList $ concat $ do
x <- bagToList $ mapBag errMsgDiagnostic $ unionManyBags $ map Compat.getMessages closure_errs
x <- map errMsgDiagnostic closure_errs
DriverHomePackagesNotClosed us <- pure x
pure us
isBad ci = (homeUnitId_ (componentDynFlags ci)) `OS.member` bad_units
Expand Down Expand Up @@ -1223,6 +1233,6 @@ showPackageSetupException PackageSetupException{..} = unwords
, "failed to load packages:", message <> "."
, "\nPlease ensure that ghcide is compiled with the same GHC installation as the project."]

renderPackageSetupException :: FilePath -> PackageSetupException -> (NormalizedFilePath, ShowDiagnostic, Diagnostic)
renderPackageSetupException :: FilePath -> PackageSetupException -> FileDiagnostic
renderPackageSetupException fp e =
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) (toNormalizedFilePath' fp) (T.pack $ showPackageSetupException e)
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) (toNormalizedFilePath' fp) (T.pack $ showPackageSetupException e) Nothing
13 changes: 8 additions & 5 deletions ghcide/session-loader/Development/IDE/Session/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Development.IDE.Session.Diagnostics where
import Control.Applicative
import Control.Lens
import Control.Monad
import qualified Data.Aeson as Aeson
import Data.List
Expand All @@ -27,11 +28,13 @@ data CradleErrorDetails =
Depicts the cradle error in a user-friendly way.
-}
renderCradleError :: CradleError -> Cradle a -> NormalizedFilePath -> FileDiagnostic
renderCradleError (CradleError deps _ec ms) cradle nfp
| HieBios.isCabalCradle cradle =
let (fp, showDiag, diag) = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp $ T.unlines $ map T.pack userFriendlyMessage in
(fp, showDiag, diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}})
| otherwise = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp $ T.unlines $ map T.pack userFriendlyMessage
renderCradleError (CradleError deps _ec ms) cradle nfp =
let noDetails =
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp (T.unlines $ map T.pack userFriendlyMessage) Nothing
in
if HieBios.isCabalCradle cradle
then noDetails & fdLspDiagnosticL %~ \diag -> diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}}
else noDetails
where
absDeps = fmap (cradleRootDir cradle </>) deps
userFriendlyMessage :: [String]
Expand Down
128 changes: 82 additions & 46 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import qualified Data.Set as Set
import qualified GHC as G
import qualified GHC.Runtime.Loader as Loader
import GHC.Tc.Gen.Splice
import GHC.Types.Error
import GHC.Types.ForeignStubs
import GHC.Types.HpcInfo
import GHC.Types.TypeEnv
Expand All @@ -130,6 +131,8 @@ import GHC.Unit.Module.Warnings
import Development.IDE.Core.FileStore (shareFilePath)
#endif

import Development.IDE.GHC.Compat.Driver (hscTypecheckRenameWithDiagnostics)

--Simple constants to make sure the source is consistently named
sourceTypecheck :: T.Text
sourceTypecheck = "typecheck"
Expand Down Expand Up @@ -157,8 +160,12 @@ computePackageDeps
-> IO (Either [FileDiagnostic] [UnitId])
computePackageDeps env pkg = do
case lookupUnit env pkg of
Nothing -> return $ Left [ideErrorText (toNormalizedFilePath' noFilePath) $
T.pack $ "unknown package: " ++ show pkg]
Nothing ->
return $ Left
[ ideErrorText
(toNormalizedFilePath' noFilePath)
(T.pack $ "unknown package: " ++ show pkg)
]
Just pkgInfo -> return $ Right $ unitDepends pkgInfo

newtype TypecheckHelpers
Expand All @@ -179,20 +186,24 @@ typecheckModule (IdeDefer defer) hsc tc_helpers pm = do
case initialized of
Left errs -> return (errs, Nothing)
Right hscEnv -> do
(warnings, etcm) <- withWarnings sourceTypecheck $ \tweak ->
etcm <-
let
session = tweak (hscSetFlags dflags hscEnv)
-- TODO: maybe settings ms_hspp_opts is unnecessary?
mod_summary'' = modSummary { ms_hspp_opts = hsc_dflags session}
-- TODO: maybe setting ms_hspp_opts is unnecessary?
mod_summary' = modSummary { ms_hspp_opts = hsc_dflags hscEnv}
in
catchSrcErrors (hsc_dflags hscEnv) sourceTypecheck $ do
tcRnModule session tc_helpers $ demoteIfDefer pm{pm_mod_summary = mod_summary''}
let errorPipeline = unDefer . hideDiag dflags . tagDiag
diags = map errorPipeline warnings
deferredError = any fst diags
tcRnModule hscEnv tc_helpers $ demoteIfDefer pm{pm_mod_summary = mod_summary'}
case etcm of
Left errs -> return (map snd diags ++ errs, Nothing)
Right tcm -> return (map snd diags, Just $ tcm{tmrDeferredError = deferredError})
Left errs -> return (errs, Nothing)
Right tcm ->
let addReason diag =
map (Just (diagnosticReason (errMsgDiagnostic diag)),) $
diagFromErrMsg sourceTypecheck (hsc_dflags hscEnv) diag
errorPipeline = map (unDefer . hideDiag dflags . tagDiag) . addReason
diags = concatMap errorPipeline $ Compat.getMessages $ tmrWarnings tcm
deferredError = any fst diags
in
return (map snd diags, Just $ tcm{tmrDeferredError = deferredError})
where
demoteIfDefer = if defer then demoteTypeErrorsToWarnings else id

Expand Down Expand Up @@ -358,9 +369,9 @@ tcRnModule hsc_env tc_helpers pmod = do
let ms = pm_mod_summary pmod
hsc_env_tmp = hscSetFlags (ms_hspp_opts ms) hsc_env

((tc_gbl_env', mrn_info), splices, mod_env)
(((tc_gbl_env', mrn_info), warning_messages), splices, mod_env)
<- captureSplicesAndDeps tc_helpers hsc_env_tmp $ \hscEnvTmp ->
do hscTypecheckRename hscEnvTmp ms $
do hscTypecheckRenameWithDiagnostics hscEnvTmp ms $
HsParsedModule { hpm_module = parsedSource pmod
, hpm_src_files = pm_extra_src_files pmod
}
Expand All @@ -372,7 +383,7 @@ tcRnModule hsc_env tc_helpers pmod = do
mod_env_anns = map (\(mod, hash) -> Annotation (ModuleTarget mod) $ toSerialized BS.unpack hash)
(moduleEnvToList mod_env)
tc_gbl_env = tc_gbl_env' { tcg_ann_env = extendAnnEnvList (tcg_ann_env tc_gbl_env') mod_env_anns }
pure (TcModuleResult pmod rn_info tc_gbl_env splices False mod_env)
pure (TcModuleResult pmod rn_info tc_gbl_env splices False mod_env warning_messages)


-- Note [Clearing mi_globals after generating an iface]
Expand Down Expand Up @@ -535,8 +546,14 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
source = "compile"
catchErrs x = x `catches`
[ Handler $ return . (,Nothing) . diagFromGhcException source dflags
, Handler $ return . (,Nothing) . diagFromString source DiagnosticSeverity_Error (noSpan "<internal>")
. (("Error during " ++ T.unpack source) ++) . show @SomeException
, Handler $ \diag ->
return
( diagFromString
source DiagnosticSeverity_Error (noSpan "<internal>")
("Error during " ++ T.unpack source ++ show @SomeException diag)
Nothing
, Nothing
)
]

-- | Whether we should run the -O0 simplifier when generating core.
Expand Down Expand Up @@ -660,15 +677,16 @@ unDefer (Just (WarningWithFlag Opt_WarnDeferredOutOfScopeVariables), fd) = (True
unDefer ( _ , fd) = (False, fd)

upgradeWarningToError :: FileDiagnostic -> FileDiagnostic
upgradeWarningToError (nfp, sh, fd) =
(nfp, sh, fd{_severity = Just DiagnosticSeverity_Error, _message = warn2err $ _message fd}) where
upgradeWarningToError =
fdLspDiagnosticL %~ \diag -> diag {_severity = Just DiagnosticSeverity_Error, _message = warn2err $ _message diag}
where
warn2err :: T.Text -> T.Text
warn2err = T.intercalate ": error:" . T.splitOn ": warning:"

hideDiag :: DynFlags -> (Maybe DiagnosticReason, FileDiagnostic) -> (Maybe DiagnosticReason, FileDiagnostic)
hideDiag originalFlags (w@(Just (WarningWithFlag warning)), (nfp, _sh, fd))
hideDiag originalFlags (w@(Just (WarningWithFlag warning)), fd)
| not (wopt warning originalFlags)
= (w, (nfp, HideDiag, fd))
= (w, fd { fdShouldShowDiagnostic = HideDiag })
hideDiag _originalFlags t = t

-- | Warnings which lead to a diagnostic tag
Expand All @@ -692,18 +710,18 @@ unnecessaryDeprecationWarningFlags
tagDiag :: (Maybe DiagnosticReason, FileDiagnostic) -> (Maybe DiagnosticReason, FileDiagnostic)

#if MIN_VERSION_ghc(9,7,0)
tagDiag (w@(Just (WarningWithCategory cat)), (nfp, sh, fd))
tagDiag (w@(Just (WarningWithCategory cat)), fd)
| cat == defaultWarningCategory -- default warning category is for deprecations
= (w, (nfp, sh, fd { _tags = Just $ DiagnosticTag_Deprecated : concat (_tags fd) }))
tagDiag (w@(Just (WarningWithFlags warnings)), (nfp, sh, fd))
= (w, fd & fdLspDiagnosticL %~ \diag -> diag { _tags = Just $ DiagnosticTag_Deprecated : concat (_tags diag) })
tagDiag (w@(Just (WarningWithFlags warnings)), fd)
| tags <- mapMaybe requiresTag (toList warnings)
= (w, (nfp, sh, fd { _tags = Just $ tags ++ concat (_tags fd) }))
= (w, fd & fdLspDiagnosticL %~ \diag -> diag { _tags = Just $ tags ++ concat (_tags diag) })
#else
tagDiag (w@(Just (WarningWithFlag warning)), (nfp, sh, fd))
tagDiag (w@(Just (WarningWithFlag warning)), fd)
| Just tag <- requiresTag warning
= (w, (nfp, sh, fd { _tags = Just $ tag : concat (_tags fd) }))
= (w, fd & fdLspDiagnosticL %~ \diag -> diag { _tags = Just $ tag : concat (_tags diag) })
#endif
where
where
requiresTag :: WarningFlag -> Maybe DiagnosticTag
#if !MIN_VERSION_ghc(9,7,0)
-- doesn't exist on 9.8, we use WarningWithCategory instead
Expand Down Expand Up @@ -859,16 +877,25 @@ handleGenerationErrors :: DynFlags -> T.Text -> IO () -> IO [FileDiagnostic]
handleGenerationErrors dflags source action =
action >> return [] `catches`
[ Handler $ return . diagFromGhcException source dflags
, Handler $ return . diagFromString source DiagnosticSeverity_Error (noSpan "<internal>")
. (("Error during " ++ T.unpack source) ++) . show @SomeException
, Handler $ \(exception :: SomeException) -> return $
diagFromString
source DiagnosticSeverity_Error (noSpan "<internal>")
("Error during " ++ T.unpack source ++ show exception)
Nothing
]

handleGenerationErrors' :: DynFlags -> T.Text -> IO (Maybe a) -> IO ([FileDiagnostic], Maybe a)
handleGenerationErrors' dflags source action =
fmap ([],) action `catches`
[ Handler $ return . (,Nothing) . diagFromGhcException source dflags
, Handler $ return . (,Nothing) . diagFromString source DiagnosticSeverity_Error (noSpan "<internal>")
. (("Error during " ++ T.unpack source) ++) . show @SomeException
, Handler $ \(exception :: SomeException) ->
return
( diagFromString
source DiagnosticSeverity_Error (noSpan "<internal>")
("Error during " ++ T.unpack source ++ show exception)
Nothing
, Nothing
)
]


Expand Down Expand Up @@ -1048,7 +1075,7 @@ parseHeader dflags filename contents = do
let loc = mkRealSrcLoc (Util.mkFastString filename) 1 1
case unP Compat.parseHeader (initParserState (initParserOpts dflags) contents loc) of
PFailedWithErrorMessages msgs ->
throwE $ diagFromErrMsgs sourceParser dflags $ msgs dflags
throwE $ diagFromGhcErrorMessages sourceParser dflags $ msgs dflags
POk pst rdr_module -> do
let (warns, errs) = renderMessages $ getPsMessages pst

Expand All @@ -1062,9 +1089,9 @@ parseHeader dflags filename contents = do
-- errors are those from which a parse tree just can't
-- be produced.
unless (null errs) $
throwE $ diagFromErrMsgs sourceParser dflags errs
throwE $ diagFromGhcErrorMessages sourceParser dflags errs

let warnings = diagFromErrMsgs sourceParser dflags warns
let warnings = diagFromGhcErrorMessages sourceParser dflags warns
return (warnings, rdr_module)

-- | Given a buffer, flags, and file path, produce a
Expand All @@ -1081,18 +1108,28 @@ parseFileContents env customPreprocessor filename ms = do
dflags = ms_hspp_opts ms
contents = fromJust $ ms_hspp_buf ms
case unP Compat.parseModule (initParserState (initParserOpts dflags) contents loc) of
PFailedWithErrorMessages msgs -> throwE $ diagFromErrMsgs sourceParser dflags $ msgs dflags
PFailedWithErrorMessages msgs ->
throwE $ diagFromGhcErrorMessages sourceParser dflags $ msgs dflags
POk pst rdr_module ->
let
psMessages = getPsMessages pst
in
do
let IdePreprocessedSource preproc_warns errs parsed = customPreprocessor rdr_module

unless (null errs) $
throwE $ diagFromStrings sourceParser DiagnosticSeverity_Error errs

let preproc_warnings = diagFromStrings sourceParser DiagnosticSeverity_Warning preproc_warns
let IdePreprocessedSource preproc_warns preproc_errs parsed = customPreprocessor rdr_module
let attachNoStructuredError (span, msg) = (span, msg, Nothing)

unless (null preproc_errs) $
throwE $
diagFromStrings
sourceParser
DiagnosticSeverity_Error
(fmap attachNoStructuredError preproc_errs)

let preproc_warning_file_diagnostics =
diagFromStrings
sourceParser
DiagnosticSeverity_Warning
(fmap attachNoStructuredError preproc_warns)
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env ms parsed psMessages
let (warns, errors) = renderMessages msgs

Expand All @@ -1106,8 +1143,7 @@ parseFileContents env customPreprocessor filename ms = do
-- errors are those from which a parse tree just can't
-- be produced.
unless (null errors) $
throwE $ diagFromErrMsgs sourceParser dflags errors

throwE $ diagFromGhcErrorMessages sourceParser dflags errors

-- To get the list of extra source files, we take the list
-- that the parser gave us,
Expand Down Expand Up @@ -1137,8 +1173,8 @@ parseFileContents env customPreprocessor filename ms = do
srcs2 <- liftIO $ filterM doesFileExist srcs1

let pm = ParsedModule ms parsed' srcs2
warnings = diagFromErrMsgs sourceParser dflags warns
pure (warnings ++ preproc_warnings, pm)
warnings = diagFromGhcErrorMessages sourceParser dflags warns
pure (warnings ++ preproc_warning_file_diagnostics, pm)

loadHieFile :: Compat.NameCacheUpdater -> FilePath -> IO GHC.HieFile
loadHieFile ncu f = do
Expand Down
Loading

0 comments on commit b87bdb9

Please sign in to comment.