mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 19:08:21 +08:00
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
88 lines
2.8 KiB
C++
88 lines
2.8 KiB
C++
//===-- CommandObjectExpression.h -------------------------------*- C++ -*-===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef liblldb_CommandObjectExpression_h_
|
|
#define liblldb_CommandObjectExpression_h_
|
|
|
|
#include "lldb/Core/IOHandler.h"
|
|
#include "lldb/Interpreter/CommandObject.h"
|
|
#include "lldb/Interpreter/OptionGroupBoolean.h"
|
|
#include "lldb/Interpreter/OptionGroupFormat.h"
|
|
#include "lldb/Interpreter/OptionGroupValueObjectDisplay.h"
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
#include "lldb/lldb-private-enumerations.h"
|
|
namespace lldb_private {
|
|
|
|
class CommandObjectExpression : public CommandObjectRaw,
|
|
public IOHandlerDelegate {
|
|
public:
|
|
class CommandOptions : public OptionGroup {
|
|
public:
|
|
CommandOptions();
|
|
|
|
~CommandOptions() override;
|
|
|
|
llvm::ArrayRef<OptionDefinition> GetDefinitions() override;
|
|
|
|
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value,
|
|
ExecutionContext *execution_context) override;
|
|
|
|
void OptionParsingStarting(ExecutionContext *execution_context) override;
|
|
|
|
bool top_level;
|
|
bool unwind_on_error;
|
|
bool ignore_breakpoints;
|
|
bool allow_jit;
|
|
bool show_types;
|
|
bool show_summary;
|
|
bool debug;
|
|
uint32_t timeout;
|
|
bool try_all_threads;
|
|
lldb::LanguageType language;
|
|
LanguageRuntimeDescriptionDisplayVerbosity m_verbosity;
|
|
LazyBool auto_apply_fixits;
|
|
};
|
|
|
|
CommandObjectExpression(CommandInterpreter &interpreter);
|
|
|
|
~CommandObjectExpression() override;
|
|
|
|
Options *GetOptions() override;
|
|
|
|
void HandleCompletion(CompletionRequest &request) override;
|
|
|
|
protected:
|
|
// IOHandler::Delegate functions
|
|
void IOHandlerInputComplete(IOHandler &io_handler,
|
|
std::string &line) override;
|
|
|
|
bool IOHandlerIsInputComplete(IOHandler &io_handler,
|
|
StringList &lines) override;
|
|
|
|
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
|
|
|
|
bool EvaluateExpression(llvm::StringRef expr, Stream *output_stream,
|
|
Stream *error_stream,
|
|
CommandReturnObject *result = nullptr);
|
|
|
|
void GetMultilineExpression();
|
|
|
|
OptionGroupOptions m_option_group;
|
|
OptionGroupFormat m_format_options;
|
|
OptionGroupValueObjectDisplay m_varobj_options;
|
|
OptionGroupBoolean m_repl_option;
|
|
CommandOptions m_command_options;
|
|
uint32_t m_expr_line_count;
|
|
std::string m_expr_lines; // Multi-line expression support
|
|
std::string m_fixed_expression; // Holds the current expression's fixed text.
|
|
};
|
|
|
|
} // namespace lldb_private
|
|
|
|
#endif // liblldb_CommandObjectExpression_h_
|