aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGongyu Deng <gy_deng@icloud.com>2020-08-24 18:58:17 +0200
committerRaphael Isemann <teemperor@gmail.com>2020-08-24 19:54:23 +0200
commit188f1ac301c5c6da6d2f5697952510fc39cbdd43 (patch)
treed66ddc53a0b80d4f3f9d8b52ec85d0dd0bf720d9
parent116affb18dfc8c48ad0bd5134b42a51e34ad6fd8 (diff)
downloadllvm-188f1ac301c5c6da6d2f5697952510fc39cbdd43.zip
llvm-188f1ac301c5c6da6d2f5697952510fc39cbdd43.tar.gz
llvm-188f1ac301c5c6da6d2f5697952510fc39cbdd43.tar.bz2
[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
-rw-r--r--lldb/include/lldb/Interpreter/CommandCompletions.h5
-rw-r--r--lldb/source/Commands/CommandCompletions.cpp16
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp2
-rw-r--r--lldb/source/Commands/CommandObjectType.cpp42
-rw-r--r--lldb/source/Interpreter/CommandObject.cpp2
-rw-r--r--lldb/test/API/functionalities/completion/TestCompletion.py6
6 files changed, 69 insertions, 4 deletions
diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h
index b90e81c..c80bde0 100644
--- a/lldb/include/lldb/Interpreter/CommandCompletions.h
+++ b/lldb/include/lldb/Interpreter/CommandCompletions.h
@@ -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
diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp
index 9221830..0ea6d42 100644
--- a/lldb/source/Commands/CommandCompletions.cpp
+++ b/lldb/source/Commands/CommandCompletions.cpp
@@ -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;
+ });
+}
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 3cd4ad8..b6af481 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -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);
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index b23f91d..d820e7a 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -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();
diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp
index b57323c..58e54e8 100644
--- a/lldb/source/Interpreter/CommandObject.cpp
+++ b/lldb/source/Interpreter/CommandObject.cpp
@@ -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." },
diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py
index 2423aec..e2b0032 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -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"])