From 3ce57e012110519c1d3a49fc98959a64634d5d8f Mon Sep 17 00:00:00 2001 From: Gongyu Deng Date: Tue, 11 Aug 2020 10:32:55 +0200 Subject: [PATCH] [lldb] type language common completion 1. Added a new common completion TypeLanguages to provide a list of supporting languages; 2. Bound the completion to eArgTypeLanguage; 3. Added a related test case. --- lldb/include/lldb/Interpreter/CommandCompletions.h | 6 +++++- lldb/source/Commands/CommandCompletions.cpp | 12 ++++++++++++ lldb/source/Interpreter/CommandObject.cpp | 2 +- lldb/test/API/functionalities/completion/TestCompletion.py | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lldb/include/lldb/Interpreter/CommandCompletions.h b/lldb/include/lldb/Interpreter/CommandCompletions.h index 55ab5d8..deaf39e 100644 --- a/lldb/include/lldb/Interpreter/CommandCompletions.h +++ b/lldb/include/lldb/Interpreter/CommandCompletions.h @@ -38,10 +38,11 @@ public: eBreakpointCompletion = (1u << 10), eProcessPluginCompletion = (1u << 11), eDisassemblyFlavorCompletion = (1u << 12), + eTypeLanguageCompletion = (1u << 13), // 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. - eCustomCompletion = (1u << 13) + eCustomCompletion = (1u << 14) }; static bool InvokeCommonCompletionCallbacks( @@ -99,6 +100,9 @@ public: static void DisassemblyFlavors(CommandInterpreter &interpreter, CompletionRequest &request, SearchFilter *searcher); + + static void TypeLanguages(CommandInterpreter &interpreter, + CompletionRequest &request, SearchFilter *searcher); }; } // namespace lldb_private diff --git a/lldb/source/Commands/CommandCompletions.cpp b/lldb/source/Commands/CommandCompletions.cpp index 69d7f78..795aabd 100644 --- a/lldb/source/Commands/CommandCompletions.cpp +++ b/lldb/source/Commands/CommandCompletions.cpp @@ -18,6 +18,7 @@ #include "lldb/Interpreter/OptionValueProperties.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Variable.h" +#include "lldb/Target/Language.h" #include "lldb/Target/RegisterContext.h" #include "lldb/Utility/FileSpec.h" #include "lldb/Utility/StreamString.h" @@ -60,6 +61,7 @@ bool CommandCompletions::InvokeCommonCompletionCallbacks( {eBreakpointCompletion, CommandCompletions::Breakpoints}, {eProcessPluginCompletion, CommandCompletions::ProcessPluginNames}, {eDisassemblyFlavorCompletion, CommandCompletions::DisassemblyFlavors}, + {eTypeLanguageCompletion, CommandCompletions::TypeLanguages}, {eNoCompletion, nullptr} // This one has to be last in the list. }; @@ -606,3 +608,13 @@ void CommandCompletions::DisassemblyFlavors(CommandInterpreter &interpreter, request.TryCompleteCurrentArg(flavor); } } + +void CommandCompletions::TypeLanguages(CommandInterpreter &interpreter, + CompletionRequest &request, + SearchFilter *searcher) { + for (int bit : + Language::GetLanguagesSupportingTypeSystems().bitvector.set_bits()) { + request.TryCompleteCurrentArg( + Language::GetNameForLanguageType(static_cast(bit))); + } +} diff --git a/lldb/source/Interpreter/CommandObject.cpp b/lldb/source/Interpreter/CommandObject.cpp index 946ea81..40b6749 100644 --- a/lldb/source/Interpreter/CommandObject.cpp +++ b/lldb/source/Interpreter/CommandObject.cpp @@ -1062,7 +1062,7 @@ CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr }, { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" }, { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." }, - { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, + { eArgTypeLanguage, "source-language", CommandCompletions::eTypeLanguageCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." }, { eArgTypeFileLineColumn, "linespec", CommandCompletions::eNoCompletion, { nullptr, false }, "A source specifier in the form file:line[:column]" }, { 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." }, diff --git a/lldb/test/API/functionalities/completion/TestCompletion.py b/lldb/test/API/functionalities/completion/TestCompletion.py index 99dcda4..2a75763 100644 --- a/lldb/test/API/functionalities/completion/TestCompletion.py +++ b/lldb/test/API/functionalities/completion/TestCompletion.py @@ -536,6 +536,9 @@ class CommandLineCompletionTestCase(TestBase): self.complete_from_to('register write rbx ', []) + def test_common_completion_type_language(self): + self.complete_from_to('type category -l ', ['c']) + def test_complete_breakpoint_with_ids(self): """These breakpoint subcommands should be completed with a list of breakpoint ids""" -- 2.7.4