mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 11:21:40 +00:00
formatter: Remove colon line prefix with no source
If a diagnostic has no Source information, don't start the diagnostic line with a colon. Bug: tint:282 Change-Id: I80c4103e31556b2769d4b4c2a98dce21a2e1c233 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31662 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
06c892a6ec
commit
1a61e8613e
@ -137,13 +137,17 @@ void Formatter::format(const Diagnostic& diag, State& state) const {
|
|||||||
|
|
||||||
state.set_style({Color::kDefault, true});
|
state.set_style({Color::kDefault, true});
|
||||||
|
|
||||||
|
bool emit_colon = true;
|
||||||
if (style_.print_file && src.file != nullptr && !src.file->path.empty()) {
|
if (style_.print_file && src.file != nullptr && !src.file->path.empty()) {
|
||||||
state << src.file->path;
|
state << src.file->path;
|
||||||
if (rng.begin.line > 0) {
|
if (rng.begin.line > 0) {
|
||||||
state << ":" << rng.begin;
|
state << ":" << rng.begin;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (rng.begin.line > 0) {
|
||||||
state << rng.begin;
|
state << rng.begin;
|
||||||
|
} else {
|
||||||
|
// No position infomation was printed, so don't start the line with a colon.
|
||||||
|
emit_colon = false;
|
||||||
}
|
}
|
||||||
if (style_.print_severity) {
|
if (style_.print_severity) {
|
||||||
switch (diag.severity) {
|
switch (diag.severity) {
|
||||||
@ -157,11 +161,16 @@ void Formatter::format(const Diagnostic& diag, State& state) const {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
state << " " << diag.severity;
|
state << " " << diag.severity << ": ";
|
||||||
|
// A colon was just printed, don't repeat it.
|
||||||
|
emit_colon = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.set_style({Color::kDefault, true});
|
state.set_style({Color::kDefault, true});
|
||||||
state << ": " << diag.message;
|
if (emit_colon) {
|
||||||
|
state << ": ";
|
||||||
|
}
|
||||||
|
state << diag.message;
|
||||||
|
|
||||||
if (style_.print_line && src.file != nullptr && rng.begin.line > 0) {
|
if (style_.print_line && src.file != nullptr && rng.begin.line > 0) {
|
||||||
state.newline();
|
state.newline();
|
||||||
|
@ -53,6 +53,14 @@ TEST_F(DiagFormatterTest, Simple) {
|
|||||||
ASSERT_EQ(expect, got);
|
ASSERT_EQ(expect, got);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DiagFormatterTest, SimpleNoSource) {
|
||||||
|
Formatter fmt{{false, false, false}};
|
||||||
|
Diagnostic diag{Severity::Info, Source{}, "no source!"};
|
||||||
|
auto got = fmt.format(List{diag});
|
||||||
|
auto* expect = "no source!";
|
||||||
|
ASSERT_EQ(expect, got);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(DiagFormatterTest, WithFile) {
|
TEST_F(DiagFormatterTest, WithFile) {
|
||||||
Formatter fmt{{true, false, false}};
|
Formatter fmt{{true, false, false}};
|
||||||
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
|
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user