[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:
parent
6ba63d8851
commit
ef06dd4328
|
@ -113,8 +113,6 @@ public:
|
||||||
|
|
||||||
Args &GetParsedLine() { return m_parsed_line; }
|
Args &GetParsedLine() { return m_parsed_line; }
|
||||||
|
|
||||||
const Args &GetPartialParsedLine() const { return m_partial_parsed_line; }
|
|
||||||
|
|
||||||
const Args::ArgEntry &GetParsedArg() {
|
const Args::ArgEntry &GetParsedArg() {
|
||||||
return GetParsedLine()[GetCursorIndex()];
|
return GetParsedLine()[GetCursorIndex()];
|
||||||
}
|
}
|
||||||
|
@ -123,7 +121,6 @@ public:
|
||||||
void ShiftArguments() {
|
void ShiftArguments() {
|
||||||
m_cursor_index--;
|
m_cursor_index--;
|
||||||
m_parsed_line.Shift();
|
m_parsed_line.Shift();
|
||||||
m_partial_parsed_line.Shift();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCursorIndex(size_t i) { m_cursor_index = i; }
|
void SetCursorIndex(size_t i) { m_cursor_index = i; }
|
||||||
|
@ -206,8 +203,6 @@ private:
|
||||||
unsigned m_raw_cursor_pos;
|
unsigned m_raw_cursor_pos;
|
||||||
/// The command line parsed as arguments.
|
/// The command line parsed as arguments.
|
||||||
Args m_parsed_line;
|
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.
|
/// The index of the argument in which the completion cursor is.
|
||||||
size_t m_cursor_index;
|
size_t m_cursor_index;
|
||||||
/// The cursor position in the argument indexed by m_cursor_index.
|
/// The cursor position in the argument indexed by m_cursor_index.
|
||||||
|
|
|
@ -1756,7 +1756,7 @@ void CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
|
||||||
|
|
||||||
// For any of the command completions a unique match will be a complete word.
|
// 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
|
// We got nothing on the command line, so return the list of commands
|
||||||
bool include_aliases = true;
|
bool include_aliases = true;
|
||||||
StringList new_matches, descriptions;
|
StringList new_matches, descriptions;
|
||||||
|
|
|
@ -21,17 +21,16 @@ CompletionRequest::CompletionRequest(llvm::StringRef command_line,
|
||||||
// We parse the argument up to the cursor, so the last argument in
|
// 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
|
// parsed_line is the one containing the cursor, and the cursor is after the
|
||||||
// last character.
|
// last character.
|
||||||
m_parsed_line = Args(command_line);
|
|
||||||
llvm::StringRef partial_command(command_line.substr(0, raw_cursor_pos));
|
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_index = 0;
|
||||||
m_cursor_char_position = 0;
|
m_cursor_char_position = 0;
|
||||||
} else {
|
} else {
|
||||||
m_cursor_index = m_partial_parsed_line.GetArgumentCount() - 1U;
|
m_cursor_index = GetParsedLine().GetArgumentCount() - 1U;
|
||||||
m_cursor_char_position =
|
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.
|
// 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(" ") &&
|
if (partial_command.endswith(" ") &&
|
||||||
!GetCursorArgumentPrefix().endswith(" ")) {
|
!GetCursorArgumentPrefix().endswith(" ")) {
|
||||||
m_parsed_line.AppendArgument(llvm::StringRef());
|
m_parsed_line.AppendArgument(llvm::StringRef());
|
||||||
m_partial_parsed_line.AppendArgument(llvm::StringRef());
|
|
||||||
// Set the cursor to the start of the fake argument.
|
// Set the cursor to the start of the fake argument.
|
||||||
m_cursor_index++;
|
m_cursor_index++;
|
||||||
m_cursor_char_position = 0;
|
m_cursor_char_position = 0;
|
||||||
|
|
|
@ -27,8 +27,8 @@ TEST(CompletionRequest, Constructor) {
|
||||||
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
||||||
EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos);
|
EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos);
|
||||||
|
|
||||||
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u);
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u);
|
||||||
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b");
|
EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompletionRequest, FakeLastArg) {
|
TEST(CompletionRequest, FakeLastArg) {
|
||||||
|
@ -45,8 +45,8 @@ TEST(CompletionRequest, FakeLastArg) {
|
||||||
EXPECT_EQ(request.GetCursorIndex(), 3U);
|
EXPECT_EQ(request.GetCursorIndex(), 3U);
|
||||||
EXPECT_EQ(request.GetCursorCharPosition(), 0U);
|
EXPECT_EQ(request.GetCursorCharPosition(), 0U);
|
||||||
|
|
||||||
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 4U);
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 4U);
|
||||||
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(3), "");
|
EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(3), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompletionRequest, TryCompleteCurrentArgGood) {
|
TEST(CompletionRequest, TryCompleteCurrentArgGood) {
|
||||||
|
@ -102,8 +102,8 @@ TEST(CompletionRequest, ShiftArguments) {
|
||||||
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
EXPECT_EQ(request.GetCursorIndex(), arg_index);
|
||||||
EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos);
|
EXPECT_EQ(request.GetCursorCharPosition(), arg_cursor_pos);
|
||||||
|
|
||||||
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 2u);
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 2u);
|
||||||
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(1), "b");
|
EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(1), "b");
|
||||||
|
|
||||||
// Shift away the 'a' argument.
|
// Shift away the 'a' argument.
|
||||||
request.ShiftArguments();
|
request.ShiftArguments();
|
||||||
|
@ -117,8 +117,8 @@ TEST(CompletionRequest, ShiftArguments) {
|
||||||
|
|
||||||
// Partially parsed line and cursor should be updated.
|
// Partially parsed line and cursor should be updated.
|
||||||
EXPECT_EQ(request.GetCursorIndex(), arg_index - 1U);
|
EXPECT_EQ(request.GetCursorIndex(), arg_index - 1U);
|
||||||
EXPECT_EQ(request.GetPartialParsedLine().GetArgumentCount(), 1u);
|
EXPECT_EQ(request.GetParsedLine().GetArgumentCount(), 1u);
|
||||||
EXPECT_STREQ(request.GetPartialParsedLine().GetArgumentAtIndex(0), "b");
|
EXPECT_STREQ(request.GetParsedLine().GetArgumentAtIndex(0), "b");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CompletionRequest, DuplicateFiltering) {
|
TEST(CompletionRequest, DuplicateFiltering) {
|
||||||
|
|
Loading…
Reference in New Issue