Expand Up
@@ -794,20 +794,23 @@ void CommandInterpreter::LoadCommandDictionary() {
}
int CommandInterpreter::GetCommandNamesMatchingPartialString (
const char *cmd_str, bool include_aliases, StringList &matches) {
AddNamesMatchingPartialString (m_command_dict, cmd_str, matches);
const char *cmd_str, bool include_aliases, StringList &matches,
StringList &descriptions) {
AddNamesMatchingPartialString (m_command_dict, cmd_str, matches,
&descriptions);
if (include_aliases) {
AddNamesMatchingPartialString (m_alias_dict, cmd_str, matches);
AddNamesMatchingPartialString (m_alias_dict, cmd_str, matches,
&descriptions);
}
return matches.GetSize ();
}
CommandObjectSP CommandInterpreter::GetCommandSP (llvm::StringRef cmd_str,
bool include_aliases,
bool exact,
StringList *matches ) const {
CommandObjectSP
CommandInterpreter::GetCommandSP (llvm::StringRef cmd_str, bool include_aliases,
bool exact, StringList *matches ,
StringList *descriptions ) const {
CommandObjectSP command_sp;
std::string cmd = cmd_str;
Expand Down
Expand Up
@@ -848,8 +851,8 @@ CommandObjectSP CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str,
// empty CommandObjectSP and the list of matches.
if (HasCommands ()) {
num_cmd_matches =
AddNamesMatchingPartialString (m_command_dict, cmd_str, *matches);
num_cmd_matches = AddNamesMatchingPartialString (m_command_dict, cmd_str,
*matches, descriptions );
}
if (num_cmd_matches == 1 ) {
Expand All
@@ -860,8 +863,8 @@ CommandObjectSP CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str,
}
if (include_aliases && HasAliases ()) {
num_alias_matches =
AddNamesMatchingPartialString (m_alias_dict, cmd_str, *matches);
num_alias_matches = AddNamesMatchingPartialString (m_alias_dict, cmd_str,
*matches, descriptions );
}
if (num_alias_matches == 1 ) {
Expand All
@@ -872,8 +875,8 @@ CommandObjectSP CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str,
}
if (HasUserCommands ()) {
num_user_matches =
AddNamesMatchingPartialString (m_user_dict, cmd_str, *matches);
num_user_matches = AddNamesMatchingPartialString (m_user_dict, cmd_str,
*matches, descriptions );
}
if (num_user_matches == 1 ) {
Expand All
@@ -898,6 +901,8 @@ CommandObjectSP CommandInterpreter::GetCommandSP(llvm::StringRef cmd_str,
}
} else if (matches && command_sp) {
matches->AppendString (cmd_str);
if (descriptions)
descriptions->AppendString (command_sp->GetHelp ());
}
return command_sp;
Expand Down
Expand Up
@@ -997,18 +1002,20 @@ CommandObjectSP CommandInterpreter::GetCommandSPExact(llvm::StringRef cmd_str,
return ret_val;
}
CommandObject *CommandInterpreter::GetCommandObject (llvm::StringRef cmd_str,
StringList *matches) const {
CommandObject *
CommandInterpreter::GetCommandObject (llvm::StringRef cmd_str,
StringList *matches,
StringList *descriptions) const {
CommandObject *command_obj =
GetCommandSP (cmd_str, false , true , matches).get ();
GetCommandSP (cmd_str, false , true , matches, descriptions ).get ();
// If we didn't find an exact match to the command string in the commands,
// look in the aliases.
if (command_obj)
return command_obj;
command_obj = GetCommandSP (cmd_str, true , true , matches).get ();
command_obj = GetCommandSP (cmd_str, true , true , matches, descriptions ).get ();
if (command_obj)
return command_obj;
Expand All
@@ -1023,10 +1030,12 @@ CommandObject *CommandInterpreter::GetCommandObject(llvm::StringRef cmd_str,
if (command_obj) {
if (matches)
matches->AppendString (command_obj->GetCommandName ());
if (descriptions)
descriptions->AppendString (command_obj->GetHelp ());
return command_obj;
}
return GetCommandSP (cmd_str, true , false , matches).get ();
return GetCommandSP (cmd_str, true , false , matches, descriptions ).get ();
}
bool CommandInterpreter::CommandExists (llvm::StringRef cmd) const {
Expand Down
Expand Up
@@ -1712,16 +1721,17 @@ int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
if (request.GetCursorIndex () == -1 ) {
// We got nothing on the command line, so return the list of commands
bool include_aliases = true ;
StringList new_matches;
num_command_matches =
GetCommandNamesMatchingPartialString ( " " , include_aliases, new_matches);
request.AddCompletions (new_matches);
StringList new_matches, descriptions ;
num_command_matches = GetCommandNamesMatchingPartialString (
" " , include_aliases, new_matches, descriptions );
request.AddCompletions (new_matches, descriptions );
} else if (request.GetCursorIndex () == 0 ) {
// The cursor is in the first argument, so just do a lookup in the
// dictionary.
StringList new_matches;
CommandObject *cmd_obj = GetCommandObject (
request.GetParsedLine ().GetArgumentAtIndex (0 ), &new_matches);
StringList new_matches, new_descriptions;
CommandObject *cmd_obj =
GetCommandObject (request.GetParsedLine ().GetArgumentAtIndex (0 ),
&new_matches, &new_descriptions);
if (num_command_matches == 1 && cmd_obj && cmd_obj->IsMultiwordObject () &&
new_matches.GetStringAtIndex (0 ) != nullptr &&
Expand All
@@ -1733,12 +1743,13 @@ int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
look_for_subcommand = true ;
num_command_matches = 0 ;
new_matches.DeleteStringAtIndex (0 );
new_descriptions.DeleteStringAtIndex (0 );
request.GetParsedLine ().AppendArgument (llvm::StringRef ());
request.SetCursorIndex (request.GetCursorIndex () + 1 );
request.SetCursorCharPosition (0 );
}
}
request.AddCompletions (new_matches);
request.AddCompletions (new_matches, new_descriptions );
num_command_matches = request.GetNumberOfMatches ();
}
Expand All
@@ -1762,12 +1773,13 @@ int CommandInterpreter::HandleCompletionMatches(CompletionRequest &request) {
int CommandInterpreter::HandleCompletion (
const char *current_line, const char *cursor, const char *last_char,
int match_start_point, int max_return_elements, StringList &matches) {
int match_start_point, int max_return_elements, StringList &matches,
StringList &descriptions) {
llvm::StringRef command_line (current_line, last_char - current_line);
CompletionResult result;
CompletionRequest request (command_line, cursor - current_line,
match_start_point, max_return_elements, matches);
match_start_point, max_return_elements, result);
// Don't complete comments, and if the line we are completing is just the
// history repeat character, substitute the appropriate history line.
const char *first_arg = request.GetParsedLine ().GetArgumentAtIndex (0 );
Expand All
@@ -1777,6 +1789,7 @@ int CommandInterpreter::HandleCompletion(
else if (first_arg[0 ] == CommandHistory::g_repeat_char) {
if (auto hist_str = m_command_history.FindString (first_arg)) {
matches.InsertStringAtIndex (0 , *hist_str);
descriptions.InsertStringAtIndex (0 , " Previous command history event" );
return -2 ;
} else
return 0 ;
Expand All
@@ -1787,13 +1800,16 @@ int CommandInterpreter::HandleCompletion(
lldbassert (max_return_elements == -1 );
int num_command_matches = HandleCompletionMatches (request);
result.GetMatches (matches);
result.GetDescriptions (descriptions);
if (num_command_matches <= 0 )
return num_command_matches;
if (request.GetParsedLine ().GetArgumentCount () == 0 ) {
// If we got an empty string, insert nothing.
matches.InsertStringAtIndex (0 , " " );
descriptions.InsertStringAtIndex (0 , " " );
} else {
// Now figure out if there is a common substring, and if so put that in
// element 0, otherwise put an empty string in element 0.
Expand All
@@ -1815,6 +1831,7 @@ int CommandInterpreter::HandleCompletion(
common_prefix.push_back (' ' );
}
matches.InsertStringAtIndex (0 , common_prefix.c_str ());
descriptions.InsertStringAtIndex (0 , " " );
}
return num_command_matches;
}
Expand Down