mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[lldb][NFC] Add CompletionRequest::AppendEmptyArgument
This is the only legitimate use we currently have for modifying a CompletionRequest. Add a utility function for this purpose and remove the remaining setters which go against the idea of having an immutable CompletionRequest. llvm-svn: 372858
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user