[Lldb-commits] [lldb] Centralize the handling of completion for simple argument lists. (PR #82085)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Sat Feb 17 11:08:52 PST 2024


================
@@ -305,6 +305,42 @@ 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)
+    return; // Maybe this should be an assert, this shouldn't be possible.
+  
+  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);
+
----------------
clayborg wrote:

If we can handle `N` completion types, this code could be put into a function and run multiple times with a different index, or we can just make a loop

https://github.com/llvm/llvm-project/pull/82085


More information about the lldb-commits mailing list