diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2022-06-15 11:45:33 +0100 |
---|---|---|
committer | sheaf <sam.derbyshire@gmail.com> | 2022-10-18 16:15:49 +0200 |
commit | e1bbd36841e19812c7ed544b66256da82ce68fd5 (patch) | |
tree | 5e524caae7e938509097b95bf0069317ed58db91 /ghc | |
parent | ba4bd4a48223bc9b215cfda138a5de9f99c87cdf (diff) | |
download | haskell-e1bbd36841e19812c7ed544b66256da82ce68fd5.tar.gz |
Allow configuration of error message printing
This MR implements the idea of #21731 that the printing of a diagnostic
method should be configurable at the printing time.
The interface of the `Diagnostic` class is modified from:
```
class Diagnostic a where
diagnosticMessage :: a -> DecoratedSDoc
diagnosticReason :: a -> DiagnosticReason
diagnosticHints :: a -> [GhcHint]
```
to
```
class Diagnostic a where
type DiagnosticOpts a
defaultDiagnosticOpts :: DiagnosticOpts a
diagnosticMessage :: DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticReason :: a -> DiagnosticReason
diagnosticHints :: a -> [GhcHint]
```
and so each `Diagnostic` can implement their own configuration record
which can then be supplied by a client in order to dictate how to print
out the error message.
At the moment this only allows us to implement #21722 nicely but in
future it is more natural to separate the configuration of how much
information we put into an error message and how much we decide to print
out of it.
Updates Haddock submodule
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/GHCi/UI.hs | 2 | ||||
-rw-r--r-- | ghc/Main.hs | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 6cbf4dffb9..4efb35f35e 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -3136,7 +3136,7 @@ newDynFlags interactive_only minus_opts = do idflags0 <- GHC.getInteractiveDynFlags (idflags1, leftovers, warns) <- DynFlags.parseDynamicFlagsCmdLine idflags0 lopts - liftIO $ handleFlagWarnings logger (initDiagOpts idflags1) warns + liftIO $ handleFlagWarnings logger (initPrintConfig idflags1) (initDiagOpts idflags1) warns when (not $ null leftovers) (throwGhcException . CmdLineError $ "Some flags have not been recognized: " diff --git a/ghc/Main.hs b/ghc/Main.hs index 16075284c0..ae862a7014 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -247,7 +247,7 @@ main' postLoadMode units dflags0 args flagWarnings = do handleSourceError (\e -> do GHC.printException e liftIO $ exitWith (ExitFailure 1)) $ do - liftIO $ handleFlagWarnings logger4 (initDiagOpts dflags4) flagWarnings' + liftIO $ handleFlagWarnings logger4 (initPrintConfig dflags4) (initDiagOpts dflags4) flagWarnings' liftIO $ showBanner postLoadMode dflags4 @@ -779,7 +779,7 @@ initMulti unitArgsFiles = do handleSourceError (\e -> do GHC.printException e liftIO $ exitWith (ExitFailure 1)) $ do - liftIO $ handleFlagWarnings logger (initDiagOpts dflags2) warns + liftIO $ handleFlagWarnings logger (initPrintConfig dflags2) (initDiagOpts dflags2) warns let (dflags3, srcs, objs) = parseTargetFiles dflags2 (map unLoc fileish_args) dflags4 = offsetDynFlags dflags3 |