aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Interpreter/CommandObject.cpp
diff options
context:
space:
mode:
authorjimingham <jingham@apple.com>2024-02-19 16:43:08 -0800
committerGitHub <noreply@github.com>2024-02-19 16:43:08 -0800
commit21631494b068d9364b8dc8f18e59adee9131a0a5 (patch)
tree35a7935c825cab7bfb61cc510da00e7b5b1350fa /lldb/source/Interpreter/CommandObject.cpp
parent4345b20508b5702c69dd1649c251c4615014dbd2 (diff)
downloadllvm-21631494b068d9364b8dc8f18e59adee9131a0a5.zip
llvm-21631494b068d9364b8dc8f18e59adee9131a0a5.tar.gz
llvm-21631494b068d9364b8dc8f18e59adee9131a0a5.tar.bz2
Centralize the handling of completion for simple argument lists. (#82085)
Most commands were adding argument completion handling by themselves, resulting in a lot of unnecessary boilerplate. In many cases, this could be done generically given the argument definition and the entries in the g_argument_table. I'm going to address this in a couple passes. In this first pass, I added handling of commands that have only one argument list, with one argument type, either single or repeated, and changed all the commands that are of this sort (and don't have other bits of business in their completers.) I also added some missing connections between arg types and completions to the table, and added a RemoteFilename and RemotePath to use in places where we were using the Remote completers. Those arguments used to say they were "files" but they were in fact remote files. I also added a module arg type to use where we were using the module completer. In that case, we should call the argument module.
Diffstat (limited to 'lldb/source/Interpreter/CommandObject.cpp')
-rw-r--r--lldb/source/Interpreter/CommandObject.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index 6ed0fd1..93c53e8 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -305,6 +305,43 @@ void CommandObject::HandleCompletion(CompletionRequest &request) {
}
}
+void CommandObject::HandleArgumentCompletion(
+ CompletionRequest &request, OptionElementVector &opt_element_vector) {
+ size_t num_arg_entries = GetNumArgumentEntries();
+ if (num_arg_entries != 1)
+ return;
+
+ CommandArgumentEntry *entry_ptr = GetArgumentEntryAtIndex(0);
+ if (!entry_ptr) {
+ assert(entry_ptr && "We said there was one entry, but there wasn't.");
+ return; // Not worth crashing if asserts are off...
+ }
+
+ CommandArgumentEntry &entry = *entry_ptr;
+ // For now, we only handle the simple case of one homogenous argument type.
+ if (entry.size() != 1)
+ return;
+
+ // Look up the completion type, and if it has one, invoke it:
+ const CommandObject::ArgumentTableEntry *arg_entry =
+ FindArgumentDataByType(entry[0].arg_type);
+ const ArgumentRepetitionType repeat = entry[0].arg_repetition;
+
+ if (arg_entry == nullptr || arg_entry->completion_type == lldb::eNoCompletion)
+ return;
+
+ // FIXME: This should be handled higher in the Command Parser.
+ // Check the case where this command only takes one argument, and don't do
+ // the completion if we aren't on the first entry:
+ if (repeat == eArgRepeatPlain && request.GetCursorIndex() != 0)
+ return;
+
+ lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), arg_entry->completion_type, request, nullptr);
+
+}
+
+
bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
bool search_short_help,
bool search_long_help,