Add the ability to define custom completers to the parsed_cmd template. (#109062)

If your arguments or option values are of a type that naturally uses one
of our common completion mechanisms, you will get completion for free.
But if you have your own custom values or if you want to do fancy things
like have `break set -s foo.dylib -n ba<TAB>` only complete on symbols
in foo.dylib, you can use this new mechanism to achieve that.
This commit is contained in:
jimingham
2024-09-24 10:00:00 -07:00
committed by GitHub
parent c6bf59f26b
commit 04b443e778
14 changed files with 771 additions and 82 deletions

View File

@@ -2720,6 +2720,46 @@ ScriptInterpreterPythonImpl::GetRepeatCommandForScriptedCommand(
return ret_val;
}
StructuredData::DictionarySP
ScriptInterpreterPythonImpl::HandleArgumentCompletionForScriptedCommand(
StructuredData::GenericSP impl_obj_sp, std::vector<llvm::StringRef> &args,
size_t args_pos, size_t char_in_arg) {
StructuredData::DictionarySP completion_dict_sp;
if (!impl_obj_sp || !impl_obj_sp->IsValid())
return completion_dict_sp;
{
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);
completion_dict_sp =
SWIGBridge::LLDBSwigPythonHandleArgumentCompletionForScriptedCommand(
static_cast<PyObject *>(impl_obj_sp->GetValue()), args, args_pos,
char_in_arg);
}
return completion_dict_sp;
}
StructuredData::DictionarySP
ScriptInterpreterPythonImpl::HandleOptionArgumentCompletionForScriptedCommand(
StructuredData::GenericSP impl_obj_sp, llvm::StringRef &long_option,
size_t char_in_arg) {
StructuredData::DictionarySP completion_dict_sp;
if (!impl_obj_sp || !impl_obj_sp->IsValid())
return completion_dict_sp;
{
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);
completion_dict_sp = SWIGBridge::
LLDBSwigPythonHandleOptionArgumentCompletionForScriptedCommand(
static_cast<PyObject *>(impl_obj_sp->GetValue()), long_option,
char_in_arg);
}
return completion_dict_sp;
}
/// In Python, a special attribute __doc__ contains the docstring for an object
/// (function, method, class, ...) if any is defined Otherwise, the attribute's
/// value is None.