Author: Gongyu Deng Date: 2020-08-11T10:27:04+02:00 New Revision: 31fd64ac57a2005c0691b8870e28b4421cf67047
URL: https://github.com/llvm/llvm-project/commit/31fd64ac57a2005c0691b8870e28b4421cf67047 DIFF: https://github.com/llvm/llvm-project/commit/31fd64ac57a2005c0691b8870e28b4421cf67047.diff LOG: [lldb] tab completion for 'command delete/unalias' Provided dedicated tab completions for `command delete/unalias`. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D81128 Added: Modified: lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/Commands/CommandObjectCommands.cpp lldb/test/API/functionalities/completion/TestCompletion.py Removed: ################################################################################ diff --git a/lldb/include/lldb/Interpreter/CommandInterpreter.h b/lldb/include/lldb/Interpreter/CommandInterpreter.h index 72638f3d807f..6ef22c1a28c1 100644 --- a/lldb/include/lldb/Interpreter/CommandInterpreter.h +++ b/lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -501,6 +501,12 @@ class CommandInterpreter : public Broadcaster, 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 index eaf22344fafa..92730b6111bb 100644 --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/lldb/source/Commands/CommandObjectCommands.cpp @@ -618,6 +618,17 @@ class CommandObjectCommandsUnalias : public CommandObjectParsed { ~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 @@ class CommandObjectCommandsDelete : public CommandObjectParsed { ~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 index 3e7878dcbdaa..99dcda4b4cf2 100644 --- a/lldb/test/API/functionalities/completion/TestCompletion.py +++ b/lldb/test/API/functionalities/completion/TestCompletion.py @@ -401,6 +401,13 @@ def test_command_script_delete(self): 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("", [ _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits