Skip to content

Commit 461f859

Browse files
[lldb] Treat user aliases the same as built-ins when tab completing (llvm#65974)
Previously we would check all built-ins first for suggestions, then check built-ins and aliases. This meant that if you had an alias brkpt -> breakpoint, "br" would complete to "breakpoint". Instead of giving you the choice of "brkpt" or "breakpoint".
1 parent 99594ba commit 461f859

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ void CommandInterpreter::Initialize() {
508508
if (cmd_obj_sp) {
509509
AddAlias("history", cmd_obj_sp);
510510
}
511+
512+
cmd_obj_sp = GetCommandSPExact("help");
513+
if (cmd_obj_sp) {
514+
AddAlias("h", cmd_obj_sp);
515+
}
511516
}
512517

513518
void CommandInterpreter::Clear() {
@@ -1227,36 +1232,11 @@ CommandObject *
12271232
CommandInterpreter::GetCommandObject(llvm::StringRef cmd_str,
12281233
StringList *matches,
12291234
StringList *descriptions) const {
1230-
CommandObject *command_obj =
1231-
GetCommandSP(cmd_str, false, true, matches, descriptions).get();
1232-
1233-
// If we didn't find an exact match to the command string in the commands,
1234-
// look in the aliases.
1235-
1236-
if (command_obj)
1237-
return command_obj;
1238-
1239-
command_obj = GetCommandSP(cmd_str, true, true, matches, descriptions).get();
1240-
1241-
if (command_obj)
1242-
return command_obj;
1243-
1244-
// If there wasn't an exact match then look for an inexact one in just the
1245-
// commands
1246-
command_obj = GetCommandSP(cmd_str, false, false, nullptr).get();
1247-
1248-
// Finally, if there wasn't an inexact match among the commands, look for an
1249-
// inexact match in both the commands and aliases.
1250-
1251-
if (command_obj) {
1252-
if (matches)
1253-
matches->AppendString(command_obj->GetCommandName());
1254-
if (descriptions)
1255-
descriptions->AppendString(command_obj->GetHelp());
1256-
return command_obj;
1257-
}
1258-
1259-
return GetCommandSP(cmd_str, true, false, matches, descriptions).get();
1235+
// Try to find a match among commands and aliases. Allowing inexact matches,
1236+
// but perferring exact matches.
1237+
return GetCommandSP(cmd_str, /*include_aliases=*/true, /*exact=*/false,
1238+
matches, descriptions)
1239+
.get();
12601240
}
12611241

12621242
CommandObject *CommandInterpreter::GetUserCommandObject(

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,19 +618,15 @@ def test_command_unalias(self):
618618

619619
def test_command_aliases(self):
620620
self.runCmd("command alias brkpt breakpoint")
621-
# If there is an unambiguous completion from the built-in commands,
622-
# we choose that.
623-
self.complete_from_to("br", "breakpoint")
624-
# Only if there is not, do we then look for an unambiguous completion
625-
# from the user defined aliases.
621+
# Exact matches are chosen if possible, even if there are longer
622+
# completions we could use.
623+
self.complete_from_to("b", "b ")
624+
# Aliases are included in possible completions.
625+
self.complete_from_to("br", ["breakpoint", "brkpt"])
626+
# An alias can be the chosen completion.
626627
self.complete_from_to("brk", "brkpt")
627628

628-
# Aliases are included when there's no exact match.
629-
self.runCmd("command alias play breakpoint")
630-
self.complete_from_to("pl", ["plugin", "platform", "play"])
631-
632-
# That list can also contain only aliases if there's no built-ins to
633-
# match.
629+
# The list can contain only aliases if there's no built-ins to match.
634630
self.runCmd("command alias test_1 breakpoint")
635631
self.runCmd("command alias test_2 breakpoint")
636632
self.complete_from_to("test_", ["test_1", "test_2"])

0 commit comments

Comments
 (0)