Use DiagnosticEmitter for phase-specific types (#5188)

Given the namespacing of `Diagnostics` in #5173, now we can use
`DiagnosticEmitter` for phase-specific emitters. This is consistent with
how we do `Context`, and also check had started this with
`DiagnosticBuilder` in anticipation of the namespacing.

Also renames `Emitter::DiagnosticBuilder` to `Emitter::Builder` for
consistency with other `Diagnostics` entities.

In check, I'm still splitting `DiagnosticEmitterBase` and
`DiagnosticEmitter` just to keep the emitter definition separate from
the context.

Also cleans up some incorrect check diagnostic emitter dependencies in
lower.
This commit is contained in:
Jon Ross-Perkins
2025-03-27 00:41:30 +00:00
committed by GitHub
parent 9d3e1d3c55
commit 0a3efb76ed
17 changed files with 87 additions and 87 deletions
+7 -5
View File
@@ -19,15 +19,16 @@
namespace Carbon::LanguageServer {
namespace {
// A consumer for turning diagnostics into a `textDocument/publishDiagnostics`
// notification.
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics
class PublishDiagnosticConsumer : public Diagnostics::Consumer {
class DiagnosticConsumer : public Diagnostics::Consumer {
public:
// Initializes params with the target file information.
explicit PublishDiagnosticConsumer(Context* context,
const clang::clangd::URIForFile& uri,
std::optional<int64_t> version)
explicit DiagnosticConsumer(Context* context,
const clang::clangd::URIForFile& uri,
std::optional<int64_t> version)
: context_(context), params_{.uri = uri, .version = version} {}
// Turns a diagnostic into an LSP diagnostic.
@@ -98,6 +99,7 @@ class PublishDiagnosticConsumer : public Diagnostics::Consumer {
Context* context_;
clang::clangd::PublishDiagnosticsParams params_;
};
} // namespace
auto Context::File::SetText(Context& context, std::optional<int64_t> version,
llvm::StringRef text) -> void {
@@ -109,7 +111,7 @@ auto Context::File::SetText(Context& context, std::optional<int64_t> version,
source_.reset();
// A consumer to gather diagnostics for the file.
PublishDiagnosticConsumer consumer(&context, uri_, version);
DiagnosticConsumer consumer(&context, uri_, version);
// TODO: Make the processing asynchronous, to better handle rapid text
// updates.