[Lldb-commits] [lldb] 188f1ac - [lldb] type category name common completion
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 24 10:54:48 PDT 2020
Author: Gongyu Deng
Date: 2020-08-24T19:54:23+02:00
New Revision: 188f1ac301c5c6da6d2f5697952510fc39cbdd43
URL: https://github.com/llvm/llvm-project/commit/188f1ac301c5c6da6d2f5697952510fc39cbdd43
DIFF: https://github.com/llvm/llvm-project/commit/188f1ac301c5c6da6d2f5697952510fc39cbdd43.diff
LOG: [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
Added:
Modified:
lldb/include/lldb/Interpreter/CommandCompletions.h
lldb/source/Commands/CommandCompletions.cpp
lldb/source/Commands/CommandObjectTarget.cpp
lldb/source/Commands/CommandObjectType.cpp
lldb/source/Interpreter/CommandObject.cpp
lldb/test/API/functionalities/completion/TestCompletion.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h
index b90e81cb95a8..c80bde0e719b 100644
--- a/lldb/include/lldb/Interpreter/CommandCompletions.h
+++ b/lldb/include/lldb/Interpreter/CommandCompletions.h
@@ -49,6 +49,7 @@ class CommandCompletions {
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 @@ class CommandCompletions {
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 9221830b6460..0ea6d4288169 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 3cd4ad88afc7..b6af481090d7 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -4725,8 +4725,6 @@ class CommandObjectTargetStopHookDelete : public CommandObjectParsed {
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 b23f91de0ce6..d820e7abd21f 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -1769,6 +1769,14 @@ class CommandObjectTypeCategoryDefine : public CommandObjectParsed {
~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 @@ class CommandObjectTypeCategoryEnable : public CommandObjectParsed {
~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 @@ class CommandObjectTypeCategoryDelete : public CommandObjectParsed {
~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 @@ class CommandObjectTypeCategoryDisable : public CommandObjectParsed {
~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 @@ class CommandObjectTypeCategoryList : public CommandObjectParsed {
~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 b57323c32790..58e54e84dc8c 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 2423aecc2075..e2b003219a00 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -468,6 +468,12 @@ def test_common_completion_thread_index(self):
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"])
More information about the lldb-commits
mailing list