2010-06-09 00:52:24 +08:00
|
|
|
//===-- CommandObjectHelp.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
#include "CommandObjectHelp.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Interpreter/CommandObjectMultiword.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// CommandObjectHelp
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage(
|
2019-02-13 14:25:41 +08:00
|
|
|
Stream *s, llvm::StringRef command, llvm::StringRef prefix,
|
|
|
|
llvm::StringRef subcommand, bool include_upropos,
|
|
|
|
bool include_type_lookup) {
|
2016-11-17 05:34:22 +08:00
|
|
|
if (!s || command.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string command_str = command.str();
|
|
|
|
std::string prefix_str = prefix.str();
|
|
|
|
std::string subcommand_str = subcommand.str();
|
|
|
|
const std::string &lookup_str = !subcommand_str.empty() ? subcommand_str : command_str;
|
|
|
|
s->Printf("'%s' is not a known command.\n", command_str.c_str());
|
|
|
|
s->Printf("Try '%shelp' to see a current list of commands.\n",
|
|
|
|
prefix.str().c_str());
|
2019-02-13 14:25:41 +08:00
|
|
|
if (include_upropos) {
|
2016-11-17 05:34:22 +08:00
|
|
|
s->Printf("Try '%sapropos %s' for a list of related commands.\n",
|
|
|
|
prefix_str.c_str(), lookup_str.c_str());
|
|
|
|
}
|
|
|
|
if (include_type_lookup) {
|
|
|
|
s->Printf("Try '%stype lookup %s' for information on types, methods, "
|
|
|
|
"functions, modules, etc.",
|
|
|
|
prefix_str.c_str(), lookup_str.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-03-01 07:22:53 +08:00
|
|
|
}
|
|
|
|
|
2016-07-15 06:03:10 +08:00
|
|
|
CommandObjectHelp::CommandObjectHelp(CommandInterpreter &interpreter)
|
2016-09-07 04:57:50 +08:00
|
|
|
: CommandObjectParsed(interpreter, "help", "Show a list of all debugger "
|
|
|
|
"commands, or give details "
|
|
|
|
"about a specific command.",
|
2016-07-15 06:03:10 +08:00
|
|
|
"help [<cmd-name>]"),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_options() {
|
|
|
|
CommandArgumentEntry arg;
|
|
|
|
CommandArgumentData command_arg;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Define the first (and only) variant of this arg.
|
|
|
|
command_arg.arg_type = eArgTypeCommandName;
|
|
|
|
command_arg.arg_repetition = eArgRepeatStar;
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// There is only one variant this argument could be; put it into the argument
|
|
|
|
// entry.
|
|
|
|
arg.push_back(command_arg);
|
2010-10-05 06:28:36 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Push the data for the first argument into the m_arguments vector.
|
|
|
|
m_arguments.push_back(arg);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 08:58:29 +08:00
|
|
|
CommandObjectHelp::~CommandObjectHelp() = default;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
[lldb] Let table gen create command option initializers.
Summary:
We currently have man large arrays containing initializers for our command options.
These tables are tricky maintain as we don't have any good place to check them for consistency and
it's also hard to read (`nullptr, {}, 0` is not very descriptive).
This patch fixes this by letting table gen generate those tables. This way we can have a more readable
syntax for this (especially for all the default arguments) and we can let TableCheck check them
for consistency (e.g. an option with an optional argument can't have `eArgTypeNone`, naming of flags', etc.).
Also refactoring the related data structures can now be done without changing the hundred of option initializers.
For example, this line:
```
{LLDB_OPT_SET_ALL, false, "hide-aliases", 'a', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Hide aliases in the command list."},
```
becomes this:
```
def hide_aliases : Option<"hide-aliases", "a">, Desc<"Hide aliases in the command list.">;
```
For now I just moved a few initializers to the new format to demonstrate the change. I'll slowly migrate the other
option initializers tables in separate patches.
Reviewers: JDevlieghere, davide, sgraenitz
Reviewed By: JDevlieghere
Subscribers: jingham, xiaobai, labath, mgorny, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D64365
llvm-svn: 365908
2019-07-12 23:30:55 +08:00
|
|
|
#define LLDB_OPTIONS_help
|
2019-07-16 17:27:02 +08:00
|
|
|
#include "CommandOptions.inc"
|
2011-09-10 01:49:36 +08:00
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition>
|
|
|
|
CommandObjectHelp::CommandOptions::GetDefinitions() {
|
2016-09-23 05:06:13 +08:00
|
|
|
return llvm::makeArrayRef(g_help_options);
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool CommandObjectHelp::DoExecute(Args &command, CommandReturnObject &result) {
|
|
|
|
CommandObject::CommandMap::iterator pos;
|
|
|
|
CommandObject *cmd_obj;
|
|
|
|
const size_t argc = command.GetArgumentCount();
|
2011-09-10 01:49:36 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// 'help' doesn't take any arguments, other than command names. If argc is
|
|
|
|
// 0, we show the user all commands (aliases and user commands if asked for).
|
|
|
|
// Otherwise every argument must be the name of a command or a sub-command.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (argc == 0) {
|
|
|
|
uint32_t cmd_types = CommandInterpreter::eCommandTypesBuiltin;
|
|
|
|
if (m_options.m_show_aliases)
|
|
|
|
cmd_types |= CommandInterpreter::eCommandTypesAliases;
|
|
|
|
if (m_options.m_show_user_defined)
|
|
|
|
cmd_types |= CommandInterpreter::eCommandTypesUserDef;
|
|
|
|
if (m_options.m_show_hidden)
|
|
|
|
cmd_types |= CommandInterpreter::eCommandTypesHidden;
|
|
|
|
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
m_interpreter.GetHelp(result, cmd_types); // General help
|
|
|
|
} else {
|
|
|
|
// Get command object for the first command argument. Only search built-in
|
|
|
|
// command dictionary.
|
|
|
|
StringList matches;
|
2016-12-09 09:08:29 +08:00
|
|
|
auto command_name = command[0].ref;
|
|
|
|
cmd_obj = m_interpreter.GetCommandObject(command_name, &matches);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (cmd_obj != nullptr) {
|
|
|
|
StringList matches;
|
|
|
|
bool all_okay = true;
|
|
|
|
CommandObject *sub_cmd_obj = cmd_obj;
|
|
|
|
// Loop down through sub_command dictionaries until we find the command
|
2016-10-06 07:40:23 +08:00
|
|
|
// object that corresponds to the help command entered.
|
2016-09-07 04:57:50 +08:00
|
|
|
std::string sub_command;
|
2016-10-06 07:40:23 +08:00
|
|
|
for (auto &entry : command.entries().drop_front()) {
|
|
|
|
sub_command = entry.ref;
|
2016-09-07 04:57:50 +08:00
|
|
|
matches.Clear();
|
|
|
|
if (sub_cmd_obj->IsAlias())
|
|
|
|
sub_cmd_obj =
|
|
|
|
((CommandAlias *)sub_cmd_obj)->GetUnderlyingCommand().get();
|
|
|
|
if (!sub_cmd_obj->IsMultiwordObject()) {
|
|
|
|
all_okay = false;
|
2016-10-06 07:40:23 +08:00
|
|
|
break;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
CommandObject *found_cmd;
|
|
|
|
found_cmd =
|
|
|
|
sub_cmd_obj->GetSubcommandObject(sub_command.c_str(), &matches);
|
2016-10-06 07:40:23 +08:00
|
|
|
if (found_cmd == nullptr || matches.GetSize() > 1) {
|
2016-09-07 04:57:50 +08:00
|
|
|
all_okay = false;
|
2016-10-06 07:40:23 +08:00
|
|
|
break;
|
|
|
|
} else
|
2016-09-07 04:57:50 +08:00
|
|
|
sub_cmd_obj = found_cmd;
|
2010-07-07 06:46:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!all_okay || (sub_cmd_obj == nullptr)) {
|
|
|
|
std::string cmd_string;
|
|
|
|
command.GetCommandString(cmd_string);
|
|
|
|
if (matches.GetSize() >= 2) {
|
|
|
|
StreamString s;
|
|
|
|
s.Printf("ambiguous command %s", cmd_string.c_str());
|
|
|
|
size_t num_matches = matches.GetSize();
|
|
|
|
for (size_t match_idx = 0; match_idx < num_matches; match_idx++) {
|
|
|
|
s.Printf("\n\t%s", matches.GetStringAtIndex(match_idx));
|
|
|
|
}
|
|
|
|
s.Printf("\n");
|
2016-11-17 05:15:24 +08:00
|
|
|
result.AppendError(s.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
} else if (!sub_cmd_obj) {
|
|
|
|
StreamString error_msg_stream;
|
|
|
|
GenerateAdditionalHelpAvenuesMessage(
|
|
|
|
&error_msg_stream, cmd_string.c_str(),
|
|
|
|
m_interpreter.GetCommandPrefix(), sub_command.c_str());
|
2016-11-17 05:15:24 +08:00
|
|
|
result.AppendError(error_msg_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
GenerateAdditionalHelpAvenuesMessage(
|
|
|
|
&result.GetOutputStream(), cmd_string.c_str(),
|
|
|
|
m_interpreter.GetCommandPrefix(), sub_command.c_str());
|
|
|
|
result.GetOutputStream().Printf(
|
|
|
|
"\nThe closest match is '%s'. Help on it follows.\n\n",
|
2016-10-06 05:14:38 +08:00
|
|
|
sub_cmd_obj->GetCommandName().str().c_str());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sub_cmd_obj->GenerateHelpText(result);
|
2018-12-21 09:45:28 +08:00
|
|
|
std::string alias_full_name;
|
|
|
|
// Don't use AliasExists here, that only checks exact name matches. If
|
|
|
|
// the user typed a shorter unique alias name, we should still tell them
|
|
|
|
// it was an alias.
|
|
|
|
if (m_interpreter.GetAliasFullName(command_name, alias_full_name)) {
|
2016-09-07 04:57:50 +08:00
|
|
|
StreamString sstr;
|
2018-12-21 09:45:28 +08:00
|
|
|
m_interpreter.GetAlias(alias_full_name)->GetAliasExpansion(sstr);
|
2016-09-07 04:57:50 +08:00
|
|
|
result.GetOutputStream().Printf("\n'%s' is an abbreviation for %s\n",
|
2016-12-09 09:08:29 +08:00
|
|
|
command[0].c_str(), sstr.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else if (matches.GetSize() > 0) {
|
|
|
|
Stream &output_strm = result.GetOutputStream();
|
|
|
|
output_strm.Printf("Help requested with ambiguous command name, possible "
|
|
|
|
"completions:\n");
|
|
|
|
const size_t match_count = matches.GetSize();
|
|
|
|
for (size_t i = 0; i < match_count; i++) {
|
|
|
|
output_strm.Printf("\t%s\n", matches.GetStringAtIndex(i));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Maybe the user is asking for help about a command argument rather than
|
|
|
|
// a command.
|
|
|
|
const CommandArgumentType arg_type =
|
2016-12-09 09:08:29 +08:00
|
|
|
CommandObject::LookupArgumentName(command_name);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (arg_type != eArgTypeLastArg) {
|
|
|
|
Stream &output_strm = result.GetOutputStream();
|
|
|
|
CommandObject::GetArgumentHelp(output_strm, arg_type, m_interpreter);
|
|
|
|
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
|
|
|
} else {
|
|
|
|
StreamString error_msg_stream;
|
2016-12-09 09:08:29 +08:00
|
|
|
GenerateAdditionalHelpAvenuesMessage(&error_msg_stream, command_name,
|
|
|
|
m_interpreter.GetCommandPrefix(),
|
|
|
|
"");
|
2016-11-17 05:15:24 +08:00
|
|
|
result.AppendError(error_msg_stream.GetString());
|
2016-09-07 04:57:50 +08:00
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.Succeeded();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
void CommandObjectHelp::HandleCompletion(CompletionRequest &request) {
|
2016-09-07 04:57:50 +08:00
|
|
|
// Return the completions of the commands in the help system:
|
Refactoring for for the internal command line completion API (NFC)
Summary:
This patch refactors the internal completion API. It now takes (as far as possible) a single
CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest
contains a common superset of the different parameters as far as it makes sense. This includes
the raw command line string and raw cursor position, which should make the `expr` command
possible to implement (at least without hacks that reconstruct the command line from the args).
This patch is not intended to change the observable behavior of lldb in any way. It's also as
minimal as possible and doesn't attempt to fix all the problems the API has.
Some Q&A:
Q: Why is this not fixing all the problems in the completion API?
A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the
smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future.
The patch also doesn't really change the internal information flow in the API, so that hopefully
saves us from ever having to revert and resubmit this humongous patch.
Q: Can we merge all the copy-pasted code in the completion methods
(like computing the current incomplete arg) into CompletionRequest class?
A: Yes, but it's out of scope for this patch.
Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern?
A: I don't want to add a getter that returns a reference to the internal integer. So we have
to use a temporary variable and the Getter/Setter instead. We don't throw exceptions
from what I can tell, so the behavior doesn't change.
Q: Why are we not owning the list of matches?
A: Because that's how the previous API works. But that should be fixed too (in another patch).
Q: Can we make the constructor simpler and compute some of the values from the plain command?
A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested
request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory
propagate the changes on the nested request back to the parent request if we don't want to change the
behavior too much).
Q: Can't we pass one const request object and then just return another result object instead of mixing
them together in one in/out parameter?
A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just
a single request object. If we make all input parameters read-only, we have a clear separation between what
is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters).
Q: Can we throw out the 'match' variables that are not implemented according to the comment?
A: We currently just forward them as in the old code to the different methods, even though I think
they are really not used. We can easily remove and readd them once every single completion method just
takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user.
Reviewers: davide, jingham, labath
Reviewed By: jingham
Subscribers: mgorny, friss, lldb-commits
Differential Revision: https://reviews.llvm.org/D48796
llvm-svn: 336146
2018-07-03 05:29:56 +08:00
|
|
|
if (request.GetCursorIndex() == 0) {
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
m_interpreter.HandleCompletionMatches(request);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
Refactoring for for the internal command line completion API (NFC)
Summary:
This patch refactors the internal completion API. It now takes (as far as possible) a single
CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest
contains a common superset of the different parameters as far as it makes sense. This includes
the raw command line string and raw cursor position, which should make the `expr` command
possible to implement (at least without hacks that reconstruct the command line from the args).
This patch is not intended to change the observable behavior of lldb in any way. It's also as
minimal as possible and doesn't attempt to fix all the problems the API has.
Some Q&A:
Q: Why is this not fixing all the problems in the completion API?
A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the
smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future.
The patch also doesn't really change the internal information flow in the API, so that hopefully
saves us from ever having to revert and resubmit this humongous patch.
Q: Can we merge all the copy-pasted code in the completion methods
(like computing the current incomplete arg) into CompletionRequest class?
A: Yes, but it's out of scope for this patch.
Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern?
A: I don't want to add a getter that returns a reference to the internal integer. So we have
to use a temporary variable and the Getter/Setter instead. We don't throw exceptions
from what I can tell, so the behavior doesn't change.
Q: Why are we not owning the list of matches?
A: Because that's how the previous API works. But that should be fixed too (in another patch).
Q: Can we make the constructor simpler and compute some of the values from the plain command?
A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested
request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory
propagate the changes on the nested request back to the parent request if we don't want to change the
behavior too much).
Q: Can't we pass one const request object and then just return another result object instead of mixing
them together in one in/out parameter?
A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just
a single request object. If we make all input parameters read-only, we have a clear separation between what
is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters).
Q: Can we throw out the 'match' variables that are not implemented according to the comment?
A: We currently just forward them as in the old code to the different methods, even though I think
they are really not used. We can easily remove and readd them once every single completion method just
takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user.
Reviewers: davide, jingham, labath
Reviewed By: jingham
Subscribers: mgorny, friss, lldb-commits
Differential Revision: https://reviews.llvm.org/D48796
llvm-svn: 336146
2018-07-03 05:29:56 +08:00
|
|
|
CommandObject *cmd_obj =
|
|
|
|
m_interpreter.GetCommandObject(request.GetParsedLine()[0].ref);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
// The command that they are getting help on might be ambiguous, in which
|
2018-05-01 00:49:04 +08:00
|
|
|
// case we should complete that, otherwise complete with the command the
|
|
|
|
// user is getting help on...
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (cmd_obj) {
|
Refactoring for for the internal command line completion API (NFC)
Summary:
This patch refactors the internal completion API. It now takes (as far as possible) a single
CompletionRequest object instead o half a dozen in/out/in-out parameters. The CompletionRequest
contains a common superset of the different parameters as far as it makes sense. This includes
the raw command line string and raw cursor position, which should make the `expr` command
possible to implement (at least without hacks that reconstruct the command line from the args).
This patch is not intended to change the observable behavior of lldb in any way. It's also as
minimal as possible and doesn't attempt to fix all the problems the API has.
Some Q&A:
Q: Why is this not fixing all the problems in the completion API?
A: Because is a blocker for the expr command completion which I want to get in ASAP. This is the
smallest patch that unblocks the expr completion patch and which allows trivial refactoring in the future.
The patch also doesn't really change the internal information flow in the API, so that hopefully
saves us from ever having to revert and resubmit this humongous patch.
Q: Can we merge all the copy-pasted code in the completion methods
(like computing the current incomplete arg) into CompletionRequest class?
A: Yes, but it's out of scope for this patch.
Q: Why the `word_complete = request.GetWordComplete(); ... ` pattern?
A: I don't want to add a getter that returns a reference to the internal integer. So we have
to use a temporary variable and the Getter/Setter instead. We don't throw exceptions
from what I can tell, so the behavior doesn't change.
Q: Why are we not owning the list of matches?
A: Because that's how the previous API works. But that should be fixed too (in another patch).
Q: Can we make the constructor simpler and compute some of the values from the plain command?
A: I think this works, but I rather want to have this in a follow up commit. Especially when making nested
request it's a bit awkward that the parsed arguments behave as both input/output (as we should in theory
propagate the changes on the nested request back to the parent request if we don't want to change the
behavior too much).
Q: Can't we pass one const request object and then just return another result object instead of mixing
them together in one in/out parameter?
A: It's hard to get keep the same behavior with that pattern, but I think we can also get a nice API with just
a single request object. If we make all input parameters read-only, we have a clear separation between what
is actually an input and what an output parameter (and hopefully we get rid of the in-out parameters).
Q: Can we throw out the 'match' variables that are not implemented according to the comment?
A: We currently just forward them as in the old code to the different methods, even though I think
they are really not used. We can easily remove and readd them once every single completion method just
takes a CompletionRequest, but for now I prefer NFC behavior from the perspective of the API user.
Reviewers: davide, jingham, labath
Reviewed By: jingham
Subscribers: mgorny, friss, lldb-commits
Differential Revision: https://reviews.llvm.org/D48796
llvm-svn: 336146
2018-07-03 05:29:56 +08:00
|
|
|
request.GetParsedLine().Shift();
|
|
|
|
request.SetCursorIndex(request.GetCursorIndex() - 1);
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
cmd_obj->HandleCompletion(request);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
[lldb][NFC] Remove WordComplete mode, make result array indexed from 0 and remove any undocumented/redundant return values
Summary:
We still have some leftovers of the old completion API in the internals of
LLDB that haven't been replaced by the new CompletionRequest. These leftovers
are:
* The return values (int/size_t) in all completion functions.
* Our result array that starts indexing at 1.
* `WordComplete` mode.
I didn't replace them back then because it's tricky to figure out what exactly they
are used for and the completion code is relatively untested. I finally got around
to writing more tests for the API and understanding the semantics, so I think it's
a good time to get rid of them.
A few words why those things should be removed/replaced:
* The return values are really cryptic, partly redundant and rarely documented.
They are also completely ignored by Xcode, so whatever information they contain will end up
breaking Xcode's completion mechanism. They are also partly impossible to even implement
as we assign negative values special meaning and our completion API sometimes returns size_t.
Completion functions are supposed to return -2 to rewrite the current line. We seem to use this
in some untested code path to expand the history repeat character to the full command, but
I haven't figured out why that doesn't work at the moment.
Completion functions return -1 to 'insert the completion character', but that isn't implemented
(even though we seem to activate this feature in LLDB sometimes).
All positive values have to match the number of results. This is obviously just redundant information
as the user can just look at the result list to get that information (which is what Xcode does).
* The result array that starts indexing at 1 is obviously unexpected. The first element of the array is
reserved for the common prefix of all completions (e.g. "foobar" and "footar" -> "foo"). The idea is
that we calculate this to make the life of the API caller easier, but obviously forcing people to have
1-based indices is not helpful (or even worse, forces them to manually copy the results to make it
0-based like Xcode has to do).
* The `WordComplete` mode indicates that LLDB should enter a space behind the completion. The
idea is that we let the top-level API know that we just provided a full completion. Interestingly we
`WordComplete` is just a single bool that somehow represents all N completions. And we always
provide full completions in LLDB, so in theory it should always be true.
The only use it currently serves is providing redundant information about whether we have a single
definitive completion or not (which we already know from the number of results we get).
This patch essentially removes `WordComplete` mode and makes the result array indexed from 0.
It also removes all return values from all internal completion functions. The only non-redundant information
they contain is about rewriting the current line (which is broken), so that functionality was moved
to the CompletionRequest API. So you can now do `addCompletion("blub", "description", CompletionMode::RewriteLine)`
to do the same.
For the SB API we emulate the old behaviour by making the array indexed from 1 again with the common
prefix at index 0. I didn't keep the special negative return codes as we either never sent them before (e.g. -2) or we
didn't even implement them in the Editline handler (e.g. -1).
I tried to keep this patch minimal and I'm aware we can probably now even further simplify a bunch of related code,
but I would prefer doing this in follow-up NFC commits
Reviewers: JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arphaman, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D66536
llvm-svn: 369624
2019-08-22 15:41:23 +08:00
|
|
|
m_interpreter.HandleCompletionMatches(request);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|