forked from OSchip/llvm-project
[lldb] type category name common completion
1. Added a new common completion TypeCategoryNames to provide a list of category names for completion; 2. Applied the completion to these commands: type category delete/enable/disable/list/define; 3. Added a related test case; 4. Bound the completion to the arguments of the type 'eArgTypeName'. Reviewed By: teemperor, JDevlieghere Differential Revision: https://reviews.llvm.org/D84124
This commit is contained in:
parent
116affb18d
commit
188f1ac301
|
@ -49,6 +49,7 @@ public:
|
|||
eProcessNameCompletion = (1u << 21),
|
||||
eRemoteDiskFileCompletion = (1u << 22),
|
||||
eRemoteDiskDirectoryCompletion = (1u << 23),
|
||||
eTypeCategoryNameCompletion = (1u << 24),
|
||||
// This item serves two purposes. It is the last element in the enum, so
|
||||
// you can add custom enums starting from here in your Option class. Also
|
||||
// if you & in this bit the base code will not process the option.
|
||||
|
@ -146,6 +147,10 @@ public:
|
|||
|
||||
static void WatchPointIDs(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request, SearchFilter *searcher);
|
||||
|
||||
static void TypeCategoryNames(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request,
|
||||
SearchFilter *searcher);
|
||||
};
|
||||
|
||||
} // namespace lldb_private
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "lldb/Core/FileSpecList.h"
|
||||
#include "lldb/Core/Module.h"
|
||||
#include "lldb/Core/PluginManager.h"
|
||||
#include "lldb/DataFormatters/DataVisualization.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Interpreter/CommandCompletions.h"
|
||||
#include "lldb/Interpreter/CommandInterpreter.h"
|
||||
|
@ -74,7 +75,9 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks(
|
|||
{eProcessIDCompletion, CommandCompletions::ProcessIDs},
|
||||
{eProcessNameCompletion, CommandCompletions::ProcessNames},
|
||||
{eRemoteDiskFileCompletion, CommandCompletions::RemoteDiskFiles},
|
||||
{eRemoteDiskDirectoryCompletion, CommandCompletions::RemoteDiskDirectories},
|
||||
{eRemoteDiskDirectoryCompletion,
|
||||
CommandCompletions::RemoteDiskDirectories},
|
||||
{eTypeCategoryNameCompletion, CommandCompletions::TypeCategoryNames},
|
||||
{eNoCompletion, nullptr} // This one has to be last in the list.
|
||||
};
|
||||
|
||||
|
@ -780,3 +783,14 @@ void CommandCompletions::WatchPointIDs(CommandInterpreter &interpreter,
|
|||
strm.GetString());
|
||||
}
|
||||
}
|
||||
|
||||
void CommandCompletions::TypeCategoryNames(CommandInterpreter &interpreter,
|
||||
CompletionRequest &request,
|
||||
SearchFilter *searcher) {
|
||||
DataVisualization::Categories::ForEach(
|
||||
[&request](const lldb::TypeCategoryImplSP &category_sp) {
|
||||
request.TryCompleteCurrentArg(category_sp->GetName(),
|
||||
category_sp->GetDescription());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4725,8 +4725,6 @@ public:
|
|||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
if (request.GetCursorIndex())
|
||||
return;
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(), CommandCompletions::eStopHookIDCompletion,
|
||||
request, nullptr);
|
||||
|
|
|
@ -1769,6 +1769,14 @@ public:
|
|||
|
||||
~CommandObjectTypeCategoryDefine() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(),
|
||||
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
@ -1865,6 +1873,14 @@ public:
|
|||
|
||||
~CommandObjectTypeCategoryEnable() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(),
|
||||
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
@ -1927,6 +1943,14 @@ public:
|
|||
|
||||
~CommandObjectTypeCategoryDelete() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(),
|
||||
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
@ -2032,6 +2056,14 @@ public:
|
|||
|
||||
~CommandObjectTypeCategoryDisable() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(),
|
||||
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
@ -2089,6 +2121,16 @@ public:
|
|||
|
||||
~CommandObjectTypeCategoryList() override = default;
|
||||
|
||||
void
|
||||
HandleArgumentCompletion(CompletionRequest &request,
|
||||
OptionElementVector &opt_element_vector) override {
|
||||
if (request.GetCursorIndex())
|
||||
return;
|
||||
CommandCompletions::InvokeCommonCompletionCallbacks(
|
||||
GetCommandInterpreter(),
|
||||
CommandCompletions::eTypeCategoryNameCompletion, request, nullptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
|
|
@ -1068,7 +1068,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
|
|||
{ eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." },
|
||||
{ eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." },
|
||||
{ eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." },
|
||||
{ eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
|
||||
{ eArgTypeName, "name", CommandCompletions::eTypeCategoryNameCompletion, { nullptr, false }, "Help text goes here." },
|
||||
{ eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
|
||||
{ eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." },
|
||||
{ eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." },
|
||||
|
|
|
@ -468,6 +468,12 @@ class CommandLineCompletionTestCase(TestBase):
|
|||
for subcommand in subcommands:
|
||||
self.complete_from_to('thread ' + subcommand + ' ', ['1'])
|
||||
|
||||
def test_common_completion_type_category_name(self):
|
||||
subcommands = ['delete', 'list', 'enable', 'disable', 'define']
|
||||
for subcommand in subcommands:
|
||||
self.complete_from_to('type category ' + subcommand + ' ', ['default'])
|
||||
self.complete_from_to('type filter add -w ', ['default'])
|
||||
|
||||
def test_command_argument_completion(self):
|
||||
"""Test completion of command arguments"""
|
||||
self.complete_from_to("watchpoint set variable -", ["-w", "-s"])
|
||||
|
|
Loading…
Reference in New Issue