Skip to content

Commit cd31204

Browse files
committed
[lldb] Fix a positioning bug in diagnostics output
The old code did not take the indentation into account.
1 parent 5587627 commit cd31204

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lldb/source/Utility/DiagnosticsRendering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ void RenderDiagnosticDetails(Stream &stream,
121121
continue;
122122

123123
stream << std::string(loc.column - x_pos, ' ') << cursor;
124-
++x_pos;
124+
x_pos = loc.column + 1;
125125
for (unsigned i = 0; i + 1 < loc.length; ++i) {
126126
stream << underline;
127-
++x_pos;
127+
x_pos += 1;
128128
}
129129
}
130130
}

lldb/unittests/Utility/DiagnosticsRenderingTest.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,27 @@ TEST_F(ErrorDisplayTest, RenderStatus) {
7474
auto line2 = lines.first;
7575
lines = lines.second.split('\n');
7676
auto line3 = lines.first;
77-
// 1234567
77+
// 1234567
7878
ASSERT_EQ(line1, "^~~ ^~~");
7979
ASSERT_EQ(line2, "| error: Y");
8080
ASSERT_EQ(line3, "error: X");
8181
}
82+
{
83+
// Test diagnostics on the same line are emitted correctly.
84+
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 2, 0, false, true};
85+
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 6, 0, false, true};
86+
std::string result =
87+
Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"},
88+
DiagnosticDetail{loc2, eSeverityError, "Y", "Y"}});
89+
auto lines = StringRef(result).split('\n');
90+
auto line1 = lines.first;
91+
lines = lines.second.split('\n');
92+
auto line2 = lines.first;
93+
lines = lines.second.split('\n');
94+
auto line3 = lines.first;
95+
// 1234567
96+
ASSERT_EQ(line1, " ^ ^");
97+
ASSERT_EQ(line2, " | error: Y");
98+
ASSERT_EQ(line3, " error: X");
99+
}
82100
}

0 commit comments

Comments
 (0)