mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 10:41:03 +01:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user