-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Fix a positioning bug in diagnostics output #116711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The old code did not take the indentation into account.
@llvm/pr-subscribers-lldb Author: Adrian Prantl (adrian-prantl) ChangesThe old code did not take the indentation into account. Full diff: https://github.com/llvm/llvm-project/pull/116711.diff 2 Files Affected:
diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp
index 208733ffc86853..dfc47ac460ac9f 100644
--- a/lldb/source/Utility/DiagnosticsRendering.cpp
+++ b/lldb/source/Utility/DiagnosticsRendering.cpp
@@ -121,10 +121,10 @@ void RenderDiagnosticDetails(Stream &stream,
continue;
stream << std::string(loc.column - x_pos, ' ') << cursor;
- ++x_pos;
+ x_pos = loc.column + 1;
for (unsigned i = 0; i + 1 < loc.length; ++i) {
stream << underline;
- ++x_pos;
+ x_pos += 1;
}
}
}
diff --git a/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp b/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
index ad2ebf7ffe1e2f..1187f3f65f27fd 100644
--- a/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
+++ b/lldb/unittests/Utility/DiagnosticsRenderingTest.cpp
@@ -74,9 +74,27 @@ TEST_F(ErrorDisplayTest, RenderStatus) {
auto line2 = lines.first;
lines = lines.second.split('\n');
auto line3 = lines.first;
- // 1234567
+ // 1234567
ASSERT_EQ(line1, "^~~ ^~~");
ASSERT_EQ(line2, "| error: Y");
ASSERT_EQ(line3, "error: X");
}
+ {
+ // Test diagnostics on the same line are emitted correctly.
+ SourceLocation loc1 = {FileSpec{"a.c"}, 1, 2, 0, false, true};
+ SourceLocation loc2 = {FileSpec{"a.c"}, 1, 6, 0, false, true};
+ std::string result =
+ Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"},
+ DiagnosticDetail{loc2, eSeverityError, "Y", "Y"}});
+ auto lines = StringRef(result).split('\n');
+ auto line1 = lines.first;
+ lines = lines.second.split('\n');
+ auto line2 = lines.first;
+ lines = lines.second.split('\n');
+ auto line3 = lines.first;
+ // 1234567
+ ASSERT_EQ(line1, " ^ ^");
+ ASSERT_EQ(line2, " | error: Y");
+ ASSERT_EQ(line3, " error: X");
+ }
}
|
felipepiovezan
approved these changes
Nov 19, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
augusto2112
approved these changes
Nov 19, 2024
adrian-prantl
added a commit
that referenced
this pull request
Nov 19, 2024
…16727) depends on #116711 [lldb] Improve rendering of inline diagnostics on the same column by fixing the indentation and printing these annotations in the original order. Before a+b+c; ^ ^ ^ | | error: 3 | |note: 2b | error: 2a error: 1 After a+b+c; ^ ^ ^ | | error: 3 | error: 2a | note: 2b error: 1
adrian-prantl
added a commit
to adrian-prantl/llvm-project
that referenced
this pull request
Nov 19, 2024
The old code did not take the indentation into account. (cherry picked from commit 8b2dff9)
adrian-prantl
added a commit
to adrian-prantl/llvm-project
that referenced
this pull request
Nov 19, 2024
…vm#116727) depends on llvm#116711 [lldb] Improve rendering of inline diagnostics on the same column by fixing the indentation and printing these annotations in the original order. Before a+b+c; ^ ^ ^ | | error: 3 | |note: 2b | error: 2a error: 1 After a+b+c; ^ ^ ^ | | error: 3 | error: 2a | note: 2b error: 1 (cherry picked from commit 6b4f675)
adrian-prantl
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Nov 19, 2024
…23-lldb-Fix-a-positioning-bug-in-diagnostics-output-116711 [Cherry-pick into stable/20240723] [lldb] Fix a positioning bug in diagnostics output (llvm#116711)
adrian-prantl
added a commit
to adrian-prantl/llvm-project
that referenced
this pull request
Dec 5, 2024
adrian-prantl
added a commit
to adrian-prantl/llvm-project
that referenced
this pull request
Dec 5, 2024
…vm#116727) depends on llvm#116711 [lldb] Improve rendering of inline diagnostics on the same column by fixing the indentation and printing these annotations in the original order. Before a+b+c; ^ ^ ^ | | error: 3 | |note: 2b | error: 2a error: 1 After a+b+c; ^ ^ ^ | | error: 3 | error: 2a | note: 2b error: 1 (cherry picked from commit 6b4f675) (cherry picked from commit 7e80550)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The old code did not take the indentation into account.