Skip to content

Commit 0f32e4d

Browse files
committed
[lldb] Fix that CompletionRequestGetRawLineUntilCursor returns the wrong result
By using m_cursor_index and not m_raw_cursor_pos in this function we return the characters until the argument index (not the character index). This means that for "foo" (cursor at the end of the string) this returns "" instead of "foo" (as the argument index is 0 for the first argument and not 4 which is the character index at the end). This lead to a crash in the REPL completion where it would cause that we would complete the string "ABC" to " " as we think the line is actually empty and we want to provide the indentation string. Note that the function has already been deleted upstream so this bug doesn't exist there.
1 parent bd31559 commit 0f32e4d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lldb/include/lldb/Utility/CompletionRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CompletionRequest {
104104

105105
llvm::StringRef GetRawLine() const { return m_command; }
106106
llvm::StringRef GetRawLineUntilCursor() const {
107-
return m_command.substr(0, m_cursor_index);
107+
return m_command.substr(0, m_raw_cursor_pos);
108108
}
109109

110110
unsigned GetRawCursorPos() const { return m_raw_cursor_pos; }

lldb/unittests/Utility/CompletionRequestTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TEST(CompletionRequest, Constructor) {
2626
EXPECT_EQ(request.GetRawCursorPos(), cursor_pos);
2727
EXPECT_EQ(request.GetCursorIndex(), arg_index);
2828
EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos);
29+
EXPECT_EQ(request.GetRawLineUntilCursor(), "a b");
2930

3031
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u);
3132
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b");

0 commit comments

Comments
 (0)