Diagnostic printing should be configurable at printing time
There are situations where we want to modify what is printed in an error message when the message is printed (rather than deciding when it's created) so it should be possible to pass configuration options to diagnosticMessage
in order to control this.
One example of this is #21722 (closed), really we want to decide when the message is printed whether to print the extra context or not, at the moment that's decided when the message is created.
It seems the design for this is quite straightforward.
Modify Diagnostic
class as follows:
class Diagnostic a where
diagnosticMessage :: a -> DecoratedSDoc
diagnosticReason :: a -> DiagnosticReason
diagnosticHints :: a -> [GhcHint]
to
class Diagnostic a where
data DiagnosticOpts a
diagnosticMessage :: DiagnosticOpts a -> a -> DecoratedSDoc
diagnosticReason :: DiagnosticOpts a -> a -> DiagnosticReason
diagnosticHints :: DiagnosticOpts a -> a -> [GhcHint]
Then the rendering can depend on whatever configuration necessary for that particular error type.