mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 10:18:14 +08:00
Add support for descriptions with command completions.
Summary:
This patch adds a framework for adding descriptions to the command completions we provide.
It also adds descriptions for completed top-level commands so that we can test this code.
Completions are in general supposed to be displayed alongside the completion itself. The descriptions
can be used to provide additional information about the completion to the user. Examples for descriptions
are function signatures when completing function calls in the expression command or the binary name
when providing completion for a symbol.
There is still some boilerplate code from the old completion API left in LLDB (mostly because the respective
APIs are reused for non-completion related purposes, so the CompletionRequest doesn't make sense to be
used), so that's why I still had to change some function signatures. Also, as the old API only passes around a
list of matches, and the descriptions are for these functions just another list, I had to add some code that
essentially just ensures that both lists are always the same side (e.g. all the manual calls to
`descriptions->AddString(X)` below a `matches->AddString(Y)` call).
The initial command descriptions that come with this patch are just reusing the existing
short help that is already added in LLDB.
An example completion with descriptions looks like this:
```
(lldb) pl
Available completions:
platform -- Commands to manage and create platforms.
plugin -- Commands for managing LLDB plugins.
```
Reviewers: #lldb, jingham
Reviewed By: #lldb, jingham
Subscribers: jingham, JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D51175
llvm-svn: 342181
This commit is contained in:
@@ -172,12 +172,10 @@ IOHandlerConfirm::IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt,
|
||||
|
||||
IOHandlerConfirm::~IOHandlerConfirm() = default;
|
||||
|
||||
int IOHandlerConfirm::IOHandlerComplete(IOHandler &io_handler,
|
||||
const char *current_line,
|
||||
const char *cursor,
|
||||
const char *last_char,
|
||||
int skip_first_n_matches,
|
||||
int max_matches, StringList &matches) {
|
||||
int IOHandlerConfirm::IOHandlerComplete(
|
||||
IOHandler &io_handler, const char *current_line, const char *cursor,
|
||||
const char *last_char, int skip_first_n_matches, int max_matches,
|
||||
StringList &matches, StringList &descriptions) {
|
||||
if (current_line == cursor) {
|
||||
if (m_default_response) {
|
||||
matches.AppendString("y");
|
||||
@@ -223,12 +221,10 @@ void IOHandlerConfirm::IOHandlerInputComplete(IOHandler &io_handler,
|
||||
}
|
||||
}
|
||||
|
||||
int IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler,
|
||||
const char *current_line,
|
||||
const char *cursor,
|
||||
const char *last_char,
|
||||
int skip_first_n_matches,
|
||||
int max_matches, StringList &matches) {
|
||||
int IOHandlerDelegate::IOHandlerComplete(
|
||||
IOHandler &io_handler, const char *current_line, const char *cursor,
|
||||
const char *last_char, int skip_first_n_matches, int max_matches,
|
||||
StringList &matches, StringList &descriptions) {
|
||||
switch (m_completion) {
|
||||
case Completion::None:
|
||||
break;
|
||||
@@ -236,14 +232,16 @@ int IOHandlerDelegate::IOHandlerComplete(IOHandler &io_handler,
|
||||
case Completion::LLDBCommand:
|
||||
return io_handler.GetDebugger().GetCommandInterpreter().HandleCompletion(
|
||||
current_line, cursor, last_char, skip_first_n_matches, max_matches,
|
||||
matches);
|
||||
|
||||
matches, descriptions);
|
||||
case Completion::Expression: {
|
||||
CompletionResult result;
|
||||
CompletionRequest request(current_line, current_line - cursor,
|
||||
skip_first_n_matches, max_matches, matches);
|
||||
skip_first_n_matches, max_matches, result);
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
io_handler.GetDebugger().GetCommandInterpreter(),
|
||||
CommandCompletions::eVariablePathCompletion, request, nullptr);
|
||||
result.GetMatches(matches);
|
||||
result.GetDescriptions(descriptions);
|
||||
|
||||
size_t num_matches = request.GetNumberOfMatches();
|
||||
if (num_matches > 0) {
|
||||
@@ -432,17 +430,15 @@ int IOHandlerEditline::FixIndentationCallback(Editline *editline,
|
||||
*editline_reader, lines, cursor_position);
|
||||
}
|
||||
|
||||
int IOHandlerEditline::AutoCompleteCallback(const char *current_line,
|
||||
const char *cursor,
|
||||
const char *last_char,
|
||||
int skip_first_n_matches,
|
||||
int max_matches,
|
||||
StringList &matches, void *baton) {
|
||||
int IOHandlerEditline::AutoCompleteCallback(
|
||||
const char *current_line, const char *cursor, const char *last_char,
|
||||
int skip_first_n_matches, int max_matches, StringList &matches,
|
||||
StringList &descriptions, void *baton) {
|
||||
IOHandlerEditline *editline_reader = (IOHandlerEditline *)baton;
|
||||
if (editline_reader)
|
||||
return editline_reader->m_delegate.IOHandlerComplete(
|
||||
*editline_reader, current_line, cursor, last_char, skip_first_n_matches,
|
||||
max_matches, matches);
|
||||
max_matches, matches, descriptions);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user