mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +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
@@ -24,8 +24,9 @@ struct Options {
|
||||
|
||||
auto Build(CommandLine::CommandBuilder& b) -> void;
|
||||
|
||||
bool verbose;
|
||||
bool fuzzing;
|
||||
bool verbose = false;
|
||||
bool fuzzing = false;
|
||||
bool include_diagnostic_kind = false;
|
||||
|
||||
ClangSubcommand clang;
|
||||
CompileSubcommand compile;
|
||||
@@ -73,6 +74,16 @@ auto Options::Build(CommandLine::CommandBuilder& b) -> void {
|
||||
},
|
||||
[&](CommandLine::FlagBuilder& arg_b) { arg_b.Set(&fuzzing); });
|
||||
|
||||
b.AddFlag(
|
||||
{
|
||||
.name = "include-diagnostic-kind",
|
||||
.help = R"""(
|
||||
When printing diagnostics, include the diagnostic kind as part of output. This
|
||||
applies to each message that forms a diagnostic, not just the primary message.
|
||||
)""",
|
||||
},
|
||||
[&](auto& arg_b) { arg_b.Set(&include_diagnostic_kind); });
|
||||
|
||||
clang.AddTo(b, &selected_subcommand);
|
||||
compile.AddTo(b, &selected_subcommand);
|
||||
format.AddTo(b, &selected_subcommand);
|
||||
@@ -84,8 +95,9 @@ auto Options::Build(CommandLine::CommandBuilder& b) -> void {
|
||||
|
||||
auto Driver::RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult {
|
||||
if (driver_env_.installation->error()) {
|
||||
*driver_env_.error_stream << "error: " << *driver_env_.installation->error()
|
||||
<< "\n";
|
||||
CARBON_DIAGNOSTIC(DriverInstallInvalid, Error, "{0}", std::string);
|
||||
driver_env_.emitter.Emit(DriverInstallInvalid,
|
||||
driver_env_.installation->error()->str());
|
||||
return {.success = false};
|
||||
}
|
||||
|
||||
@@ -95,8 +107,15 @@ auto Driver::RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult {
|
||||
args, *driver_env_.output_stream, Options::Info,
|
||||
[&](CommandLine::CommandBuilder& b) { options.Build(b); });
|
||||
|
||||
// Regardless of whether the parse succeeded, try to use the diagnostic kind
|
||||
// flag.
|
||||
driver_env_.consumer.set_include_diagnostic_kind(
|
||||
options.include_diagnostic_kind);
|
||||
|
||||
if (!result.ok()) {
|
||||
*driver_env_.error_stream << "error: " << result.error() << "\n";
|
||||
CARBON_DIAGNOSTIC(DriverCommandLineParseFailed, Error, "{0}", std::string);
|
||||
driver_env_.emitter.Emit(DriverCommandLineParseFailed,
|
||||
PrintToString(result.error()));
|
||||
return {.success = false};
|
||||
} else if (*result == CommandLine::ParseResult::MetaSuccess) {
|
||||
return {.success = true};
|
||||
|
||||
Reference in New Issue
Block a user