diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -501,6 +501,12 @@ return m_user_dict; } + const CommandObject::CommandMap &GetCommands() const { + return m_command_dict; + } + + const CommandObject::CommandMap &GetAliases() const { return m_alias_dict; } + /// Specify if the command interpreter should allow that the user can /// specify a custom exit code when calling 'quit'. void AllowExitCodeOnQuit(bool allow); diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -618,6 +618,17 @@ ~CommandObjectCommandsUnalias() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0) + return; + + for (const auto &ent : m_interpreter.GetAliases()) { + request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp()); + } + } + protected: bool DoExecute(Args &args, CommandReturnObject &result) override { CommandObject::CommandMap::iterator pos; @@ -699,6 +710,18 @@ ~CommandObjectCommandsDelete() override = default; + void + HandleArgumentCompletion(CompletionRequest &request, + OptionElementVector &opt_element_vector) override { + if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0) + return; + + for (const auto &ent : m_interpreter.GetCommands()) { + if (ent.second->IsRemovable()) + request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp()); + } + } + protected: bool DoExecute(Args &args, CommandReturnObject &result) override { CommandObject::CommandMap::iterator pos; diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py --- a/lldb/test/API/functionalities/completion/TestCompletion.py +++ b/lldb/test/API/functionalities/completion/TestCompletion.py @@ -401,6 +401,13 @@ self.runCmd("command script add -h test_desc -f none -s current usercmd1") self.check_completion_with_desc('command script delete ', [['usercmd1', 'test_desc']]) + def test_command_delete(self): + self.runCmd(r"command regex test_command s/^$/finish/ 's/([0-9]+)/frame select %1/'") + self.complete_from_to('command delete test_c', 'command delete test_command') + + def test_command_unalias(self): + self.complete_from_to('command unalias ima', 'command unalias image') + def test_completion_description_commands(self): """Test descriptions of top-level command completions""" self.check_completion_with_desc("", [