mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Switch custom error stream output to diagnostic (#4846)
This switches most error printing to use diagnostics instead of direct stream writes, even when not a specific file diagnostic. I'm allowing empty filenames for this use-case. This allows a little more specific testing to validate coverage of output using the diagnostic coverage test. I'm adding a few tests to cover things that weren't previously tested. Separately, this also forces a little more standardization in format... considering how changes like #4568 show effort being spent to _mirror_ diagnostic style, my thought is now to just use diagnostic code where possible. Note this also allows incrementally better testing of the language server; I'm changing the crash fix from #4847 in favor of diagnostic testing. --------- Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Chandler Carruth
parent
7d2958ad37
commit
7befe2ce9f
@@ -8,6 +8,7 @@
|
||||
#include "clang-tools-extra/clangd/Transport.h"
|
||||
#include "clang-tools-extra/clangd/support/Logger.h"
|
||||
#include "common/raw_string_ostream.h"
|
||||
#include "toolchain/diagnostics/diagnostic_emitter.h"
|
||||
#include "toolchain/language_server/context.h"
|
||||
#include "toolchain/language_server/incoming_messages.h"
|
||||
#include "toolchain/language_server/outgoing_messages.h"
|
||||
@@ -15,7 +16,8 @@
|
||||
namespace Carbon::LanguageServer {
|
||||
|
||||
auto Run(FILE* input_stream, llvm::raw_ostream& output_stream,
|
||||
llvm::raw_ostream& error_stream) -> ErrorOr<Success> {
|
||||
llvm::raw_ostream& error_stream, DiagnosticConsumer& consumer)
|
||||
-> bool {
|
||||
// TODO: Consider implementing a custom logger that splits vlog to
|
||||
// vlog_stream when provided. For now, this disables verbose logging.
|
||||
clang::clangd::StreamLogger logger(error_stream, clang::clangd::Logger::Info);
|
||||
@@ -36,10 +38,12 @@ auto Run(FILE* input_stream, llvm::raw_ostream& output_stream,
|
||||
if (err) {
|
||||
RawStringOstream out;
|
||||
out << err;
|
||||
return Error(out.TakeStr());
|
||||
} else {
|
||||
return Success();
|
||||
CARBON_DIAGNOSTIC(LanguageServerTransportError, Error, "{0}", std::string);
|
||||
NoLocDiagnosticEmitter emitter(&consumer);
|
||||
emitter.Emit(LanguageServerTransportError, out.TakeStr());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Carbon::LanguageServer
|
||||
|
||||
Reference in New Issue
Block a user