Author: teemperor Date: Tue Sep 24 00:22:44 2019 New Revision: 372692 URL: http://llvm.org/viewvc/llvm-project?rev=372692&view=rev Log: [lldb] Remove redundant argument lists in CompletionRequest
We currently have two lists in the CompletionRequest that we inherited from the old API: The complete list of arguments ignoring where the user requested completion and the list of arguments that stops at the cursor. Having two lists of arguments is confusing and can lead to subtle errors, so let's remove the complete list until we actually need it. Modified: lldb/trunk/include/lldb/Utility/CompletionRequest.h lldb/trunk/source/Interpreter/CommandInterpreter.cpp lldb/trunk/source/Utility/CompletionRequest.cpp lldb/trunk/unittests/Utility/CompletionRequestTest.cpp Modified: lldb/trunk/include/lldb/Utility/CompletionRequest.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/CompletionRequest.h?rev=372692&r1=372691&r2=372692&view=diff ============================================================================== --- lldb/trunk/include/lldb/Utility/CompletionRequest.h (original) +++ lldb/trunk/include/lldb/Utility/CompletionRequest.h Tue Sep 24 00:22:44 2019 @@ -113,8 +113,6 @@ public: Args &GetParsedLine() { return m_parsed_line; } - const Args &GetPartialParsedLine() const { return m_partial_parsed_line; } - const Args::ArgEntry &GetParsedArg() { return GetParsedLine()[GetCursorIndex()]; } @@ -123,7 +121,6 @@ public: void ShiftArguments() { m_cursor_index--; m_parsed_line.Shift(); - m_partial_parsed_line.Shift(); } void SetCursorIndex(size_t i) { m_cursor_index = i; } @@ -206,8 +203,6 @@ private: unsigned m_raw_cursor_pos; /// The command line parsed as arguments. Args m_parsed_line; - /// The command line until the cursor position parsed as arguments. - Args m_partial_parsed_line; /// The index of the argument in which the completion cursor is. size_t m_cursor_index; /// The cursor position in the argument indexed by m_cursor_index. Modified: lldb/trunk/source/Interpreter/CommandInterpreter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/CommandInterpreter.cpp?rev=372692&r1=372691&r2=372692&view=diff ============================================================================== --- lldb/trunk/source/Interpreter/CommandInterpreter.cpp (original) +++ lldb/trunk/source/Interpreter/CommandInterpreter.cpp Tue Sep 24 00:22:44 2019 @@ -1756,7 +1756,7 @@ void CommandInterpreter::HandleCompletio // For any of the command completions a unique match will be a complete word. - if (request.GetPartialParsedLine().GetArgumentCount() == 0) { + if (request.GetParsedLine().GetArgumentCount() == 0) { // We got nothing on the command line, so return the list of commands bool include_aliases = true; StringList new_matches, descriptions; Modified: lldb/trunk/source/Utility/CompletionRequest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/CompletionRequest.cpp?rev=372692&r1=372691&r2=372692&view=diff ============================================================================== --- lldb/trunk/source/Utility/CompletionRequest.cpp (original) +++ lldb/trunk/source/Utility/CompletionRequest.cpp Tue Sep 24 00:22:44 2019 @@ -21,17 +21,16 @@ CompletionRequest::CompletionRequest(llv // We parse the argument up to the cursor, so the last argument in // parsed_line is the one containing the cursor, and the cursor is after the // last character. - m_parsed_line = Args(command_line); llvm::StringRef partial_command(command_line.substr(0, raw_cursor_pos)); - m_partial_parsed_line = Args(partial_command); + m_parsed_line = Args(partial_command); - if (m_partial_parsed_line.GetArgumentCount() == 0) { + if (GetParsedLine().GetArgumentCount() == 0) { m_cursor_index = 0; m_cursor_char_position = 0; } else { - m_cursor_index = m_partial_parsed_line.GetArgumentCount() - 1U; + m_cursor_index = GetParsedLine().GetArgumentCount() - 1U; m_cursor_char_position = - strlen(m_partial_parsed_line.GetArgumentAtIndex(m_cursor_index)); + strlen(GetParsedLine().GetArgumentAtIndex(m_cursor_index)); } // The cursor is after a space but the space is not part of the argument. @@ -40,7 +39,6 @@ CompletionRequest::CompletionRequest(llv if (partial_command.endswith(" ") && !GetCursorArgumentPrefix().endswith(" ")) { m_parsed_line.AppendArgument(llvm::StringRef()); - m_partial_parsed_line.AppendArgument(llvm::StringRef()); // Set the cursor to the start of the fake argument. m_cursor_index++; m_cursor_char_position = 0; Modified: lldb/trunk/unittests/Utility/CompletionRequestTest.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/CompletionRequestTest.cpp?rev=372692&r1=372691&r2=372692&view=diff ============================================================================== --- lldb/trunk/unittests/Utility/CompletionRequestTest.cpp (original) +++ lldb/trunk/unittests/Utility/CompletionRequestTest.cpp Tue Sep 24 00:22:44 2019 @@ -27,8 +27,8 @@ TEST(CompletionRequest, Constructor) { EXPECT_EQ(request.GetCursorIndex(), arg_index); EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); - EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u); - EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b"); + EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u); + EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b"); } TEST(CompletionRequest, FakeLastArg) { @@ -45,8 +45,8 @@ TEST(CompletionRequest, FakeLastArg) { EXPECT_EQ(request.GetCursorIndex(), 3U); EXPECT_EQ(request.GetCursorCharPosition(), 0U); - EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 4U); - EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(3), ""); + EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 4U); + EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(3), ""); } TEST(CompletionRequest, TryCompleteCurrentArgGood) { @@ -102,8 +102,8 @@ TEST(CompletionRequest, ShiftArguments) EXPECT_EQ(request.GetCursorIndex(), arg_index); EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos); - EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u); - EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b"); + EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u); + EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b"); // Shift away the 'a' argument. request.ShiftArguments(); @@ -117,8 +117,8 @@ TEST(CompletionRequest, ShiftArguments) // Partially parsed line and cursor should be updated. EXPECT_EQ(request.GetCursorIndex(), arg_index - 1U); - EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 1u); - EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(0), "b"); + EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 1u); + EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(0), "b"); } TEST(CompletionRequest, DuplicateFiltering) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits