Autocompletion for custom commands

I’m defining some custom command around my python script for LLDB, and I was looking for having some auto-completion. Is this possible?

At present, there’s no way for a custom command to directly handle completion or describe the input structure for the command to lldb, so lldb’s command interpreter doesn’t have any way to complete it.

The quick way to fix this is to add a handle_completion method to the Class based form of the command definition. That would receive the current command line and the cursor position and would return either the characters to be inserted there, or the rewritten command, not sure which is more convenient… That’s only a partial solution, however, because it forces the script writer to re-implement completion for all the types lldb already knows how to do completion for.

The better way would be to make an SB wrapper for OptionValue, and have the __init__ method of the command class register the options & arguments it takes, including short & long option strings with the command interpreter. Then lldb could handle the parsing and completion for all the option types it knows. We could also auto-generate the syntax & options listings in “help”. We would probably also want the handle_completion as a fallback to handle the cases where lldb doesn’t know how to complete the value.

Anyway, this is a long-standing hole in the facilities for adding custom commands to lldb, but so far no-one has gotten around to filling it…

1 Like