diff options
| -rw-r--r-- | lldb/include/lldb/Utility/CompletionRequest.h | 14 | ||||
| -rw-r--r-- | lldb/source/Commands/CommandObjectMultiword.cpp | 3 | ||||
| -rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 4 | ||||
| -rw-r--r-- | lldb/unittests/Utility/CompletionRequestTest.cpp | 14 |
4 files changed, 14 insertions, 21 deletions
diff --git a/lldb/include/lldb/Utility/CompletionRequest.h b/lldb/include/lldb/Utility/CompletionRequest.h index ce8301b058e..96f202b4b6b 100644 --- a/lldb/include/lldb/Utility/CompletionRequest.h +++ b/lldb/include/lldb/Utility/CompletionRequest.h @@ -123,11 +123,15 @@ public: m_parsed_line.Shift(); } - void SetCursorIndex(size_t i) { m_cursor_index = i; } - size_t GetCursorIndex() const { return m_cursor_index; } + /// Adds an empty argument at the end of the argument list and moves + /// the cursor to this new argument. + void AppendEmptyArgument() { + m_parsed_line.AppendArgument(llvm::StringRef()); + m_cursor_index++; + m_cursor_char_position = 0; + } - void SetCursorCharPosition(size_t pos) { m_cursor_char_position = pos; } - size_t GetCursorCharPosition() const { return m_cursor_char_position; } + size_t GetCursorIndex() const { return m_cursor_index; } /// Adds a possible completion string. If the completion was already /// suggested before, it will not be added to the list of results. A copy of @@ -193,7 +197,7 @@ public: } llvm::StringRef GetCursorArgumentPrefix() const { - return GetCursorArgument().substr(0, GetCursorCharPosition()); + return GetCursorArgument().substr(0, m_cursor_char_position); } private: diff --git a/lldb/source/Commands/CommandObjectMultiword.cpp b/lldb/source/Commands/CommandObjectMultiword.cpp index e06c7335f89..c0f5d6703f8 100644 --- a/lldb/source/Commands/CommandObjectMultiword.cpp +++ b/lldb/source/Commands/CommandObjectMultiword.cpp @@ -195,8 +195,7 @@ void CommandObjectMultiword::HandleCompletion(CompletionRequest &request) { if (cmd_obj != nullptr) { if (request.GetParsedLine().GetArgumentCount() != 1) { request.GetParsedLine().Shift(); - request.SetCursorCharPosition(0); - request.GetParsedLine().AppendArgument(llvm::StringRef()); + request.AppendEmptyArgument(); cmd_obj->HandleCompletion(request); } } diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 10a80653168..71f766ed7b5 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -1779,9 +1779,7 @@ void CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) { look_for_subcommand = true; new_matches.DeleteStringAtIndex(0); new_descriptions.DeleteStringAtIndex(0); - request.GetParsedLine().AppendArgument(llvm::StringRef()); - request.SetCursorIndex(request.GetCursorIndex() + 1U); - request.SetCursorCharPosition(0); + request.AppendEmptyArgument(); } } request.AddCompletions(new_matches, new_descriptions); diff --git a/lldb/unittests/Utility/CompletionRequestTest.cpp b/lldb/unittests/Utility/CompletionRequestTest.cpp index 6e501a988de..f1971711a50 100644 --- a/lldb/unittests/Utility/CompletionRequestTest.cpp +++ b/lldb/unittests/Utility/CompletionRequestTest.cpp @@ -15,7 +15,6 @@ TEST(CompletionRequest, Constructor) { std::string command = "a bad c"; const unsigned cursor_pos = 3; const size_t arg_index = 1; - const size_t arg_cursor_pos = 1; StringList matches; CompletionResult result; @@ -25,10 +24,9 @@ TEST(CompletionRequest, Constructor) { EXPECT_STREQ(request.GetRawLine().str().c_str(), command.c_str()); EXPECT_EQ(request.GetRawCursorPos(), cursor_pos); EXPECT_EQ(request.GetCursorIndex(), arg_index); - EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u); - EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b"); + EXPECT_EQ(request.GetCursorArgumentPrefix().str(), "b"); } TEST(CompletionRequest, FakeLastArg) { @@ -43,10 +41,9 @@ TEST(CompletionRequest, FakeLastArg) { EXPECT_STREQ(request.GetRawLine().str().c_str(), command.c_str()); EXPECT_EQ(request.GetRawCursorPos(), cursor_pos); EXPECT_EQ(request.GetCursorIndex(), 3U); - EXPECT_EQ(request.GetCursorCharPosition(), 0U); EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 4U); - EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(3), ""); + EXPECT_EQ(request.GetCursorArgumentPrefix().str(), ""); } TEST(CompletionRequest, TryCompleteCurrentArgGood) { @@ -90,7 +87,6 @@ TEST(CompletionRequest, ShiftArguments) { std::string command = "a bad c"; const unsigned cursor_pos = 3; const size_t arg_index = 1; - const size_t arg_cursor_pos = 1; StringList matches; CompletionResult result; @@ -100,7 +96,6 @@ TEST(CompletionRequest, ShiftArguments) { EXPECT_STREQ(request.GetRawLine().str().c_str(), command.c_str()); EXPECT_EQ(request.GetRawCursorPos(), cursor_pos); EXPECT_EQ(request.GetCursorIndex(), arg_index); - EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u); EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b"); @@ -112,13 +107,10 @@ TEST(CompletionRequest, ShiftArguments) { EXPECT_STREQ(request.GetRawLine().str().c_str(), command.c_str()); EXPECT_EQ(request.GetRawCursorPos(), cursor_pos); - // Relative cursor position in arg is identical. - EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); - // Partially parsed line and cursor should be updated. EXPECT_EQ(request.GetCursorIndex(), arg_index - 1U); EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 1u); - EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(0), "b"); + EXPECT_EQ(request.GetCursorArgumentPrefix().str(), "b"); } TEST(CompletionRequest, DuplicateFiltering) { |

