Currently the logic for emitting diagnostics is split between 2 files: "DiagnosticReporter" and "CompilationState".
This PR pulls all this logic into its own centralized file: "DiagnosticEmitter", and then renames "DiagnosticReporter" to just "Diagnostics". Also no "CompilationState" isn't as cluttered with this emission code.
Diagnostics: this is a thin wrapper around Vec<Diagnostic>. It's sole job is to store diagnostics.
DiagnosticEmitter: It's job is to emit diagnostics. It stores config (like diagnostic-format), but doesn't store diagnostics.
I chose this instead of merging them into the existing "DiagnosticReporter" because really, these are 2 different tasks: storing and emitting. We never use both functionalities in the same place.
Now the validators, parsers, etc. only need to deal with Diagnostics.
The wrapper is trivial to construct and easy to combine together, unlike DiagnosticReporter.
So, now we can use function-chains to report errors in more places, and functions are free to return a Diagnostics instead of needing to take &mut DiagnosticReporter.
DiagnosticEmitter can be created on the fly whenever you want to emit diagnostics (really only at the end of compilation).
Simply construct it, then call emit_diagnostics(diagnostics). Clean and simple, and easier to test with!
To the reviewer: this PR isn't as large as it looks. Most of the changes were just renaming diagnostic_reporter to reporter and moving functions between files.
Currently the logic for emitting diagnostics is split between 2 files: "DiagnosticReporter" and "CompilationState". This PR pulls all this logic into its own centralized file: "DiagnosticEmitter", and then renames "DiagnosticReporter" to just "Diagnostics". Also no "CompilationState" isn't as cluttered with this emission code.
Diagnostics
: this is a thin wrapper aroundVec<Diagnostic>
. It's sole job is to store diagnostics.DiagnosticEmitter
: It's job is to emit diagnostics. It stores config (likediagnostic-format
), but doesn't store diagnostics.I chose this instead of merging them into the existing "DiagnosticReporter" because really, these are 2 different tasks: storing and emitting. We never use both functionalities in the same place.
Now the validators, parsers, etc. only need to deal with
Diagnostics
. The wrapper is trivial to construct and easy to combine together, unlikeDiagnosticReporter
. So, now we can use function-chains to report errors in more places, and functions are free to return aDiagnostics
instead of needing to take&mut DiagnosticReporter
.DiagnosticEmitter
can be created on the fly whenever you want to emit diagnostics (really only at the end of compilation). Simply construct it, then callemit_diagnostics(diagnostics)
. Clean and simple, and easier to test with!To the reviewer: this PR isn't as large as it looks. Most of the changes were just renaming
diagnostic_reporter
toreporter
and moving functions between files.