Skip to content

Allow configuration of error message printing

Matthew Pickering requested to merge wip/diagnostics-config into master

This MR implements the idea of #21731 (closed) 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 (closed) 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.

Edited by sheaf

Merge request reports