Skip to content

Commit 31fd64a

Browse files
MrHateTeemperor
authored andcommitted
[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
1 parent df91606 commit 31fd64a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ class CommandInterpreter : public Broadcaster,
501501
return m_user_dict;
502502
}
503503

504+
const CommandObject::CommandMap &GetCommands() const {
505+
return m_command_dict;
506+
}
507+
508+
const CommandObject::CommandMap &GetAliases() const { return m_alias_dict; }
509+
504510
/// Specify if the command interpreter should allow that the user can
505511
/// specify a custom exit code when calling 'quit'.
506512
void AllowExitCodeOnQuit(bool allow);

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,17 @@ class CommandObjectCommandsUnalias : public CommandObjectParsed {
618618

619619
~CommandObjectCommandsUnalias() override = default;
620620

621+
void
622+
HandleArgumentCompletion(CompletionRequest &request,
623+
OptionElementVector &opt_element_vector) override {
624+
if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0)
625+
return;
626+
627+
for (const auto &ent : m_interpreter.GetAliases()) {
628+
request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp());
629+
}
630+
}
631+
621632
protected:
622633
bool DoExecute(Args &args, CommandReturnObject &result) override {
623634
CommandObject::CommandMap::iterator pos;
@@ -699,6 +710,18 @@ class CommandObjectCommandsDelete : public CommandObjectParsed {
699710

700711
~CommandObjectCommandsDelete() override = default;
701712

713+
void
714+
HandleArgumentCompletion(CompletionRequest &request,
715+
OptionElementVector &opt_element_vector) override {
716+
if (!m_interpreter.HasCommands() || request.GetCursorIndex() != 0)
717+
return;
718+
719+
for (const auto &ent : m_interpreter.GetCommands()) {
720+
if (ent.second->IsRemovable())
721+
request.TryCompleteCurrentArg(ent.first, ent.second->GetHelp());
722+
}
723+
}
724+
702725
protected:
703726
bool DoExecute(Args &args, CommandReturnObject &result) override {
704727
CommandObject::CommandMap::iterator pos;

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ def test_command_script_delete(self):
401401
self.runCmd("command script add -h test_desc -f none -s current usercmd1")
402402
self.check_completion_with_desc('command script delete ', [['usercmd1', 'test_desc']])
403403

404+
def test_command_delete(self):
405+
self.runCmd(r"command regex test_command s/^$/finish/ 's/([0-9]+)/frame select %1/'")
406+
self.complete_from_to('command delete test_c', 'command delete test_command')
407+
408+
def test_command_unalias(self):
409+
self.complete_from_to('command unalias ima', 'command unalias image')
410+
404411
def test_completion_description_commands(self):
405412
"""Test descriptions of top-level command completions"""
406413
self.check_completion_with_desc("", [

0 commit comments

Comments
 (0)