summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r--lldb/source/Interpreter/CommandAlias.cpp17
-rw-r--r--lldb/source/Interpreter/CommandInterpreter.cpp67
-rw-r--r--lldb/source/Interpreter/CommandObject.cpp26
-rw-r--r--lldb/source/Interpreter/CommandObjectRegexCommand.cpp24
4 files changed, 62 insertions, 72 deletions
diff --git a/lldb/source/Interpreter/CommandAlias.cpp b/lldb/source/Interpreter/CommandAlias.cpp
index 7a62e285608..a4b0a0c55c0 100644
--- a/lldb/source/Interpreter/CommandAlias.cpp
+++ b/lldb/source/Interpreter/CommandAlias.cpp
@@ -114,26 +114,17 @@ bool CommandAlias::WantsCompletion() {
return false;
}
-int CommandAlias::HandleCompletion(Args &input, int &cursor_index,
- int &cursor_char_position,
- int match_start_point,
- int max_return_elements, bool &word_complete,
- StringList &matches) {
+int CommandAlias::HandleCompletion(CompletionRequest &request) {
if (IsValid())
- return m_underlying_command_sp->HandleCompletion(
- input, cursor_index, cursor_char_position, match_start_point,
- max_return_elements, word_complete, matches);
+ return m_underlying_command_sp->HandleCompletion(request);
return -1;
}
int CommandAlias::HandleArgumentCompletion(
- Args &input, int &cursor_index, int &cursor_char_position,
- OptionElementVector &opt_element_vector, int match_start_point,
- int max_return_elements, bool &word_complete, StringList &matches) {
+ CompletionRequest &request, OptionElementVector &opt_element_vector) {
if (IsValid())
return m_underlying_command_sp->HandleArgumentCompletion(
- input, cursor_index, cursor_char_position, opt_element_vector,
- match_start_point, max_return_elements, word_complete, matches);
+ request, opt_element_vector);
return -1;
}
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index cb31a4a33aa..d2014afa869 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1677,13 +1677,14 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
// We didn't find the first command object, so complete the first argument.
Args command_args(command_string);
StringList matches;
- int num_matches;
int cursor_index = 0;
int cursor_char_position = strlen(command_args.GetArgumentAtIndex(0));
- bool word_complete;
- num_matches = HandleCompletionMatches(command_args, cursor_index,
- cursor_char_position, 0, -1,
- word_complete, matches);
+ bool word_complete = true;
+ CompletionRequest request(command_line, cursor_char_position, command_args,
+ cursor_index, cursor_char_position, 0, -1,
+ word_complete, matches);
+ int num_matches = HandleCompletionMatches(request);
+ word_complete = request.GetWordComplete();
if (num_matches > 0) {
std::string error_msg;
@@ -1712,59 +1713,55 @@ bool CommandInterpreter::HandleCommand(const char *command_line,
return result.Succeeded();
}
-int CommandInterpreter::HandleCompletionMatches(
- Args &parsed_line, int &cursor_index, int &cursor_char_position,
- int match_start_point, int max_return_elements, bool &word_complete,
- StringList &matches) {
+int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
+ auto &matches = request.GetMatches();
int num_command_matches = 0;
bool look_for_subcommand = false;
// For any of the command completions a unique match will be a complete word.
- word_complete = true;
+ request.SetWordComplete(true);
- if (cursor_index == -1) {
+ if (request.GetCursorIndex() == -1) {
// We got nothing on the command line, so return the list of commands
bool include_aliases = true;
num_command_matches =
GetCommandNamesMatchingPartialString("", include_aliases, matches);
- } else if (cursor_index == 0) {
+ } else if (request.GetCursorIndex() == 0) {
// The cursor is in the first argument, so just do a lookup in the
// dictionary.
- CommandObject *cmd_obj =
- GetCommandObject(parsed_line.GetArgumentAtIndex(0), &matches);
+ CommandObject *cmd_obj = GetCommandObject(
+ request.GetParsedLine().GetArgumentAtIndex(0), &matches);
num_command_matches = matches.GetSize();
if (num_command_matches == 1 && cmd_obj && cmd_obj->IsMultiwordObject() &&
matches.GetStringAtIndex(0) != nullptr &&
- strcmp(parsed_line.GetArgumentAtIndex(0),
+ strcmp(request.GetParsedLine().GetArgumentAtIndex(0),
matches.GetStringAtIndex(0)) == 0) {
- if (parsed_line.GetArgumentCount() == 1) {
- word_complete = true;
+ if (request.GetParsedLine().GetArgumentCount() == 1) {
+ request.SetWordComplete(true);
} else {
look_for_subcommand = true;
num_command_matches = 0;
matches.DeleteStringAtIndex(0);
- parsed_line.AppendArgument(llvm::StringRef());
- cursor_index++;
- cursor_char_position = 0;
+ request.GetParsedLine().AppendArgument(llvm::StringRef());
+ request.SetCursorIndex(request.GetCursorIndex() + 1);
+ request.SetCursorCharPosition(0);
}
}
}
- if (cursor_index > 0 || look_for_subcommand) {
+ if (request.GetCursorIndex() > 0 || look_for_subcommand) {
// We are completing further on into a commands arguments, so find the
// command and tell it to complete the command. First see if there is a
// matching initial command:
CommandObject *command_object =
- GetCommandObject(parsed_line.GetArgumentAtIndex(0));
+ GetCommandObject(request.GetParsedLine().GetArgumentAtIndex(0));
if (command_object == nullptr) {
return 0;
} else {
- parsed_line.Shift();
- cursor_index--;
- num_command_matches = command_object->HandleCompletion(
- parsed_line, cursor_index, cursor_char_position, match_start_point,
- max_return_elements, word_complete, matches);
+ request.GetParsedLine().Shift();
+ request.SetCursorIndex(request.GetCursorIndex() - 1);
+ num_command_matches = command_object->HandleCompletion(request);
}
}
@@ -1778,7 +1775,8 @@ int CommandInterpreter::HandleCompletion(
// parsed_line is the one containing the cursor, and the cursor is after the
// last character.
- Args parsed_line(llvm::StringRef(current_line, last_char - current_line));
+ llvm::StringRef command_line(current_line, last_char - current_line);
+ Args parsed_line(command_line);
Args partial_parsed_line(
llvm::StringRef(current_line, cursor - current_line));
@@ -1833,10 +1831,15 @@ int CommandInterpreter::HandleCompletion(
// Only max_return_elements == -1 is supported at present:
lldbassert(max_return_elements == -1);
- bool word_complete;
- num_command_matches = HandleCompletionMatches(
- parsed_line, cursor_index, cursor_char_position, match_start_point,
- max_return_elements, word_complete, matches);
+ bool word_complete = false;
+
+ CompletionRequest request(command_line, cursor - current_line, parsed_line,
+ cursor_index, cursor_char_position,
+ match_start_point, max_return_elements,
+ word_complete, matches);
+
+ num_command_matches = HandleCompletionMatches(request);
+ word_complete = request.GetWordComplete();
if (num_command_matches <= 0)
return num_command_matches;
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 74b83d5445b..cee30b36929 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -260,18 +260,14 @@ void CommandObject::Cleanup() {
m_api_locker.unlock();
}
-int CommandObject::HandleCompletion(Args &input, int &cursor_index,
- int &cursor_char_position,
- int match_start_point,
- int max_return_elements,
- bool &word_complete, StringList &matches) {
+int CommandObject::HandleCompletion(CompletionRequest &request) {
// Default implementation of WantsCompletion() is !WantsRawCommandString().
// Subclasses who want raw command string but desire, for example, argument
// completion should override WantsCompletion() to return true, instead.
if (WantsRawCommandString() && !WantsCompletion()) {
// FIXME: Abstract telling the completion to insert the completion
// character.
- matches.Clear();
+ request.GetMatches().Clear();
return -1;
} else {
// Can we do anything generic with the options?
@@ -280,21 +276,23 @@ int CommandObject::HandleCompletion(Args &input, int &cursor_index,
OptionElementVector opt_element_vector;
if (cur_options != nullptr) {
- opt_element_vector = cur_options->ParseForCompletion(input, cursor_index);
+ opt_element_vector = cur_options->ParseForCompletion(
+ request.GetParsedLine(), request.GetCursorIndex());
bool handled_by_options;
+ bool word_complete = request.GetWordComplete();
handled_by_options = cur_options->HandleOptionCompletion(
- input, opt_element_vector, cursor_index, cursor_char_position,
- match_start_point, max_return_elements, GetCommandInterpreter(),
- word_complete, matches);
+ request.GetParsedLine(), opt_element_vector, request.GetCursorIndex(),
+ request.GetCursorCharPosition(), request.GetMatchStartPoint(),
+ request.GetMaxReturnElements(), GetCommandInterpreter(),
+ word_complete, request.GetMatches());
+ request.SetWordComplete(word_complete);
if (handled_by_options)
- return matches.GetSize();
+ return request.GetMatches().GetSize();
}
// If we got here, the last word is not an option or an option argument.
- return HandleArgumentCompletion(
- input, cursor_index, cursor_char_position, opt_element_vector,
- match_start_point, max_return_elements, word_complete, matches);
+ return HandleArgumentCompletion(request, opt_element_vector);
}
}
diff --git a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
index 2bfec0b743d..6826a2c334f 100644
--- a/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
+++ b/lldb/source/Interpreter/CommandObjectRegexCommand.cpp
@@ -99,23 +99,21 @@ bool CommandObjectRegexCommand::AddRegexCommand(const char *re_cstr,
return false;
}
-int CommandObjectRegexCommand::HandleCompletion(Args &input, int &cursor_index,
- int &cursor_char_position,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches) {
+int CommandObjectRegexCommand::HandleCompletion(CompletionRequest &request) {
if (m_completion_type_mask) {
- std::string completion_str(input.GetArgumentAtIndex(cursor_index),
- cursor_char_position);
+ std::string completion_str(
+ request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex()),
+ request.GetCursorCharPosition());
+ bool word_complete = request.GetWordComplete();
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), m_completion_type_mask, completion_str.c_str(),
- match_start_point, max_return_elements, nullptr, word_complete,
- matches);
- return matches.GetSize();
+ request.GetMatchStartPoint(), request.GetMaxReturnElements(), nullptr,
+ word_complete, request.GetMatches());
+ request.SetWordComplete(word_complete);
+ return request.GetMatches().GetSize();
} else {
- matches.Clear();
- word_complete = false;
+ request.GetMatches().Clear();
+ request.SetWordComplete(false);
}
return 0;
}
OpenPOWER on IntegriCloud