2010-06-09 00:52:24 +08:00
|
|
|
//===-- CommandObjectHelp.h -------------------------------------*- 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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef liblldb_CommandObjectHelp_h_
|
|
|
|
#define liblldb_CommandObjectHelp_h_
|
|
|
|
|
2017-03-23 07:33:16 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandObject.h"
|
2011-09-10 01:49:36 +08:00
|
|
|
#include "lldb/Interpreter/Options.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
|
|
|
|
// CommandObjectHelp
|
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
class CommandObjectHelp : public CommandObjectParsed {
|
2010-06-09 00:52:24 +08:00
|
|
|
public:
|
2010-09-18 09:14:36 +08:00
|
|
|
CommandObjectHelp(CommandInterpreter &interpreter);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2015-09-02 17:33:09 +08:00
|
|
|
~CommandObjectHelp() override;
|
2016-09-07 04:57:50 +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 HandleCompletion(CompletionRequest &request) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-01 07:22:53 +08:00
|
|
|
static void GenerateAdditionalHelpAvenuesMessage(
|
2016-11-17 05:34:22 +08:00
|
|
|
Stream *s, llvm::StringRef command, llvm::StringRef prefix,
|
2019-02-13 14:25:41 +08:00
|
|
|
llvm::StringRef subcommand, bool include_upropos = true,
|
2016-03-01 07:22:53 +08:00
|
|
|
bool include_type_lookup = true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-10 01:49:36 +08:00
|
|
|
class CommandOptions : public Options {
|
|
|
|
public:
|
2016-08-12 07:51:28 +08:00
|
|
|
CommandOptions() : Options() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-09-02 17:33:09 +08:00
|
|
|
~CommandOptions() override {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
|
|
|
ExecutionContext *execution_context) override {
|
|
|
|
Status error;
|
2012-12-04 08:32:51 +08:00
|
|
|
const int short_option = m_getopt_table[option_idx].val;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-10 01:49:36 +08:00
|
|
|
switch (short_option) {
|
|
|
|
case 'a':
|
2015-01-15 08:52:41 +08:00
|
|
|
m_show_aliases = false;
|
2011-09-10 01:49:36 +08:00
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
m_show_user_defined = false;
|
|
|
|
break;
|
2015-01-15 08:52:41 +08:00
|
|
|
case 'h':
|
|
|
|
m_show_hidden = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2011-09-10 01:49:36 +08:00
|
|
|
default:
|
2019-08-22 16:08:05 +08:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-09-10 01:49:36 +08:00
|
|
|
return error;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-10 01:49:36 +08:00
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
|
|
|
m_show_aliases = true;
|
2015-01-15 08:52:41 +08:00
|
|
|
m_show_user_defined = true;
|
|
|
|
m_show_hidden = false;
|
2011-09-10 01:49:36 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +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> GetDefinitions() override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-10 01:49:36 +08:00
|
|
|
// Instance variables to hold the values for command options.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-01-15 08:52:41 +08:00
|
|
|
bool m_show_aliases;
|
2011-09-10 01:49:36 +08:00
|
|
|
bool m_show_user_defined;
|
2015-01-15 08:52:41 +08:00
|
|
|
bool m_show_hidden;
|
2016-09-07 04:57:50 +08:00
|
|
|
};
|
|
|
|
|
2016-08-12 07:51:28 +08:00
|
|
|
Options *GetOptions() override { return &m_options; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
protected:
|
2015-09-02 17:33:09 +08:00
|
|
|
bool DoExecute(Args &command, CommandReturnObject &result) override;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-06-09 05:56:10 +08:00
|
|
|
private:
|
|
|
|
CommandOptions m_options;
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lldb_private
|
|
|
|
|
2015-09-02 17:33:09 +08:00
|
|
|
#endif // liblldb_CommandObjectHelp_h_
|