[lldb][NFC] NFC cleanup for the completion code

llvm-svn: 369632
This commit is contained in:
Raphael Isemann
2019-08-22 09:02:54 +00:00
parent 35038c914c
commit 1153dc9603
8 changed files with 120 additions and 120 deletions

View File

@@ -205,20 +205,20 @@ void CommandObjectHelp::HandleCompletion(CompletionRequest &request) {
// Return the completions of the commands in the help system:
if (request.GetCursorIndex() == 0) {
m_interpreter.HandleCompletionMatches(request);
} else {
CommandObject *cmd_obj =
m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref);
// The command that they are getting help on might be ambiguous, in which
// case we should complete that, otherwise complete with the command the
// user is getting help on...
if (cmd_obj) {
request.GetParsedLine().Shift();
request.SetCursorIndex(request.GetCursorIndex() - 1);
cmd_obj->HandleCompletion(request);
} else {
m_interpreter.HandleCompletionMatches(request);
}
return;
}
CommandObject *cmd_obj =
m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref);
// The command that they are getting help on might be ambiguous, in which
// case we should complete that, otherwise complete with the command the
// user is getting help on...
if (cmd_obj) {
request.GetParsedLine().Shift();
request.SetCursorIndex(request.GetCursorIndex() - 1);
cmd_obj->HandleCompletion(request);
return;
}
m_interpreter.HandleCompletionMatches(request);
}

View File

@@ -201,20 +201,22 @@ void CommandObjectMultiword::HandleCompletion(CompletionRequest &request) {
}
}
}
} else {
StringList new_matches;
CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches);
if (sub_command_object == nullptr) {
request.AddCompletions(new_matches);
} else {
// Remove the one match that we got from calling GetSubcommandObject.
new_matches.DeleteStringAtIndex(0);
request.AddCompletions(new_matches);
request.GetParsedLine().Shift();
request.SetCursorIndex(request.GetCursorIndex() - 1);
return sub_command_object->HandleCompletion(request);
}
return;
}
StringList new_matches;
CommandObject *sub_command_object = GetSubcommandObject(arg0, &new_matches);
if (sub_command_object == nullptr) {
request.AddCompletions(new_matches);
return;
}
// Remove the one match that we got from calling GetSubcommandObject.
new_matches.DeleteStringAtIndex(0);
request.AddCompletions(new_matches);
request.GetParsedLine().Shift();
request.SetCursorIndex(request.GetCursorIndex() - 1);
sub_command_object->HandleCompletion(request);
}
const char *CommandObjectMultiword::GetRepeatCommand(Args &current_command_args,

View File

@@ -1440,36 +1440,37 @@ public:
// We are only completing the name option for now...
if (GetDefinitions()[opt_defs_index].short_option == 'n') {
// Are we in the name?
// Are we in the name?
if (GetDefinitions()[opt_defs_index].short_option != 'n')
return false;
// Look to see if there is a -P argument provided, and if so use that
// plugin, otherwise use the default plugin.
// Look to see if there is a -P argument provided, and if so use that
// plugin, otherwise use the default plugin.
const char *partial_name = nullptr;
partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos);
const char *partial_name = nullptr;
partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos);
PlatformSP platform_sp(interpreter.GetPlatform(true));
if (platform_sp) {
ProcessInstanceInfoList process_infos;
ProcessInstanceInfoMatch match_info;
if (partial_name) {
match_info.GetProcessInfo().GetExecutableFile().SetFile(
partial_name, FileSpec::Style::native);
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
const uint32_t num_matches = process_infos.GetSize();
if (num_matches > 0) {
for (uint32_t i = 0; i < num_matches; ++i) {
request.AddCompletion(llvm::StringRef(
process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i)));
}
}
}
PlatformSP platform_sp(interpreter.GetPlatform(true));
if (!platform_sp)
return false;
ProcessInstanceInfoList process_infos;
ProcessInstanceInfoMatch match_info;
if (partial_name) {
match_info.GetProcessInfo().GetExecutableFile().SetFile(
partial_name, FileSpec::Style::native);
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
const uint32_t num_matches = process_infos.GetSize();
if (num_matches == 0)
return false;
for (uint32_t i = 0; i < num_matches; ++i) {
request.AddCompletion(
llvm::StringRef(process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i)));
}
return false;
}

View File

@@ -328,35 +328,35 @@ public:
// We are only completing the name option for now...
if (GetDefinitions()[opt_defs_index].short_option == 'n') {
// Are we in the name?
// Are we in the name?
if (GetDefinitions()[opt_defs_index].short_option != 'n')
return false;
// Look to see if there is a -P argument provided, and if so use that
// plugin, otherwise use the default plugin.
// Look to see if there is a -P argument provided, and if so use that
// plugin, otherwise use the default plugin.
const char *partial_name = nullptr;
partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos);
const char *partial_name = nullptr;
partial_name = request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos);
PlatformSP platform_sp(interpreter.GetPlatform(true));
if (platform_sp) {
ProcessInstanceInfoList process_infos;
ProcessInstanceInfoMatch match_info;
if (partial_name) {
match_info.GetProcessInfo().GetExecutableFile().SetFile(
partial_name, FileSpec::Style::native);
match_info.SetNameMatchType(NameMatch::StartsWith);
}
PlatformSP platform_sp(interpreter.GetPlatform(true));
if (!platform_sp)
return false;
ProcessInstanceInfoList process_infos;
ProcessInstanceInfoMatch match_info;
if (partial_name) {
match_info.GetProcessInfo().GetExecutableFile().SetFile(
partial_name, FileSpec::Style::native);
match_info.SetNameMatchType(NameMatch::StartsWith);
}
platform_sp->FindProcesses(match_info, process_infos);
const size_t num_matches = process_infos.GetSize();
if (num_matches > 0) {
for (size_t i = 0; i < num_matches; ++i) {
request.AddCompletion(llvm::StringRef(
process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i)));
}
if (num_matches == 0)
return false;
for (size_t i = 0; i < num_matches; ++i) {
request.AddCompletion(
llvm::StringRef(process_infos.GetProcessNameAtIndex(i),
process_infos.GetProcessNameLengthAtIndex(i)));
}
}
}
return false;
}

View File

@@ -142,26 +142,27 @@ insert-before or insert-after.");
CommandCompletions::InvokeCommonCompletionCallbacks(
GetCommandInterpreter(), CommandCompletions::eSettingsNameCompletion,
request, nullptr);
} else {
return;
}
arg =
request.GetParsedLine().GetArgumentAtIndex(request.GetCursorIndex());
if (arg) {
if (arg[0] == '-') {
// Complete option name
} else {
// Complete setting value
const char *setting_var_name =
request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
Status error;
lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue(
&m_exe_ctx, setting_var_name, false, error));
if (value_sp) {
value_sp->AutoComplete(m_interpreter, request);
}
}
}
}
if (!arg)
return;
// Complete option name
if (arg[0] != '-')
return;
// Complete setting value
const char *setting_var_name =
request.GetParsedLine().GetArgumentAtIndex(setting_var_idx);
Status error;
lldb::OptionValueSP value_sp(GetDebugger().GetPropertyValue(
&m_exe_ctx, setting_var_name, false, error));
if (!value_sp)
return;
value_sp->AutoComplete(m_interpreter, request);
}
protected:

View File

@@ -172,12 +172,9 @@ IOHandlerConfirm::~IOHandlerConfirm() = default;
void IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler,
CompletionRequest &request) {
if (request.GetRawCursorPos() == 0) {
if (m_default_response)
request.AddCompletion("y");
else
request.AddCompletion("n");
}
if (request.GetRawCursorPos() != 0)
return;
request.AddCompletion(m_default_response ? "y" : "n");
}
void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler,

View File

@@ -111,9 +111,8 @@ void OptionValueEnumeration::AutoComplete(CommandInterpreter &interpreter,
if (name.startswith(request.GetCursorArgumentPrefix()))
request.AddCompletion(name);
}
} else {
// only suggest "true" or "false" by default
return;
}
for (size_t i = 0; i < num_enumerators; ++i)
request.AddCompletion(m_enumerations.GetCStringAtIndex(i).GetStringRef());
}
}

View File

@@ -66,24 +66,24 @@ void OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
CompletionRequest &request) {
ExecutionContext exe_ctx(interpreter.GetExecutionContext());
Target *target = exe_ctx.GetTargetPtr();
if (target) {
auto prefix = request.GetCursorArgumentPrefix();
llvm::SmallVector<uint8_t, 20> uuid_bytes;
if (UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty()) {
const size_t num_modules = target->GetImages().GetSize();
for (size_t i = 0; i < num_modules; ++i) {
ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
if (module_sp) {
const UUID &module_uuid = module_sp->GetUUID();
if (module_uuid.IsValid()) {
llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
if (module_bytes.size() >= uuid_bytes.size() &&
module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) {
request.AddCompletion(module_uuid.GetAsString());
}
}
}
}
if (!target)
return;
auto prefix = request.GetCursorArgumentPrefix();
llvm::SmallVector<uint8_t, 20> uuid_bytes;
if (!UUID::DecodeUUIDBytesFromString(prefix, uuid_bytes).empty())
return;
const size_t num_modules = target->GetImages().GetSize();
for (size_t i = 0; i < num_modules; ++i) {
ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
if (!module_sp)
continue;
const UUID &module_uuid = module_sp->GetUUID();
if (!module_uuid.IsValid())
continue;
llvm::ArrayRef<uint8_t> module_bytes = module_uuid.GetBytes();
if (module_bytes.size() >= uuid_bytes.size() &&
module_bytes.take_front(uuid_bytes.size()).equals(uuid_bytes)) {
request.AddCompletion(module_uuid.GetAsString());
}
}
}