[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.

llvm-svn: 372692
This commit is contained in:
Raphael Isemann 2019-09-24 07:22:44 +00:00
parent 6ba63d8851
commit ef06dd4328
4 changed files with 13 additions and 20 deletions

View File

@ -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.

View File

@ -1756,7 +1756,7 @@ void CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
// 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;

View File

@ -21,17 +21,16 @@ CompletionRequest::CompletionRequest(llvm::StringRef command_line,
// 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(llvm::StringRef command_line,
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;

View File

@ -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) {