Skip to content

Commit 1cd99fe

Browse files
MrHateTeemperor
authored andcommitted
[lldb] tab completion for class CommandObjectTypeFormatterDelete
1. Added a dedicated completion to class `CommandObjectTypeFormatterDelete` which can be used by these commands: `type filter/format/summary/synthetic delete`; 2. Added a related test case. Reviewed By: teemperor Differential Revision: https://reviews.llvm.org/D84142
1 parent 9026d3b commit 1cd99fe

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

lldb/include/lldb/DataFormatters/FormattersContainer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ template <typename ValueType> class FormattersContainer {
202202
return m_map.size();
203203
}
204204

205+
void AutoComplete(CompletionRequest &request) {
206+
ForEach([&request](const TypeMatcher &matcher, const ValueSP &value) {
207+
request.TryCompleteCurrentArg(matcher.GetMatchString().GetStringRef());
208+
return true;
209+
});
210+
}
211+
205212
protected:
206213
FormattersContainer(const FormattersContainer &) = delete;
207214
const FormattersContainer &operator=(const FormattersContainer &) = delete;

lldb/source/Commands/CommandObjectType.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <functional>
3838
#include <memory>
3939

40+
#define CHECK_FORMATTER_KIND_MASK(VAL) \
41+
((m_formatter_kind_mask & (VAL)) == (VAL))
42+
4043
using namespace lldb;
4144
using namespace lldb_private;
4245

@@ -777,6 +780,39 @@ class CommandObjectTypeFormatterDelete : public CommandObjectParsed {
777780

778781
~CommandObjectTypeFormatterDelete() override = default;
779782

783+
void
784+
HandleArgumentCompletion(CompletionRequest &request,
785+
OptionElementVector &opt_element_vector) override {
786+
if (request.GetCursorIndex())
787+
return;
788+
789+
DataVisualization::Categories::ForEach(
790+
[this, &request](const lldb::TypeCategoryImplSP &category_sp) {
791+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemValue))
792+
category_sp->GetTypeFormatsContainer()->AutoComplete(request);
793+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexValue))
794+
category_sp->GetRegexTypeFormatsContainer()->AutoComplete(request);
795+
796+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemSummary))
797+
category_sp->GetTypeSummariesContainer()->AutoComplete(request);
798+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexSummary))
799+
category_sp->GetRegexTypeSummariesContainer()->AutoComplete(
800+
request);
801+
802+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemFilter))
803+
category_sp->GetTypeFiltersContainer()->AutoComplete(request);
804+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexFilter))
805+
category_sp->GetRegexTypeFiltersContainer()->AutoComplete(request);
806+
807+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemSynth))
808+
category_sp->GetTypeSyntheticsContainer()->AutoComplete(request);
809+
if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexSynth))
810+
category_sp->GetRegexTypeSyntheticsContainer()->AutoComplete(
811+
request);
812+
return true;
813+
});
814+
}
815+
780816
protected:
781817
virtual bool FormatterSpecificDeletion(ConstString typeCS) { return false; }
782818

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,27 @@ def test_symbol_name(self):
581581
# (anonymous namespace)::Quux().
582582
self.complete_from_to('breakpoint set -n Qu', '')
583583

584+
def test_completion_type_formatter_delete(self):
585+
self.runCmd('type filter add --child a Aoo')
586+
self.complete_from_to('type filter delete ', ['Aoo'])
587+
self.runCmd('type filter add --child b -x Boo')
588+
self.complete_from_to('type filter delete ', ['Boo'])
589+
590+
self.runCmd('type format add -f hex Coo')
591+
self.complete_from_to('type format delete ', ['Coo'])
592+
self.runCmd('type format add -f hex -x Doo')
593+
self.complete_from_to('type format delete ', ['Doo'])
594+
595+
self.runCmd('type summary add -c Eoo')
596+
self.complete_from_to('type summary delete ', ['Eoo'])
597+
self.runCmd('type summary add -x -c Foo')
598+
self.complete_from_to('type summary delete ', ['Foo'])
599+
600+
self.runCmd('type synthetic add Goo -l test')
601+
self.complete_from_to('type synthetic delete ', ['Goo'])
602+
self.runCmd('type synthetic add -x Hoo -l test')
603+
self.complete_from_to('type synthetic delete ', ['Hoo'])
604+
584605
@skipIf(archs=no_match(['x86_64']))
585606
def test_register_read_and_write_on_x86(self):
586607
"""Test the completion of the commands register read and write on x86"""

0 commit comments

Comments
 (0)