Author: Gongyu Deng
Date: 2020-08-31T14:18:07+02:00
New Revision: 1cd99fe9d4166bbe72b0b935b40bbb41cdc0a6c8

URL: 
https://github.com/llvm/llvm-project/commit/1cd99fe9d4166bbe72b0b935b40bbb41cdc0a6c8
DIFF: 
https://github.com/llvm/llvm-project/commit/1cd99fe9d4166bbe72b0b935b40bbb41cdc0a6c8.diff

LOG: [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

Added: 
    

Modified: 
    lldb/include/lldb/DataFormatters/FormattersContainer.h
    lldb/source/Commands/CommandObjectType.cpp
    lldb/test/API/functionalities/completion/TestCompletion.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h 
b/lldb/include/lldb/DataFormatters/FormattersContainer.h
index aebccbe413cc..2f56218c43a7 100644
--- a/lldb/include/lldb/DataFormatters/FormattersContainer.h
+++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h
@@ -202,6 +202,13 @@ template <typename ValueType> class FormattersContainer {
     return m_map.size();
   }
 
+  void AutoComplete(CompletionRequest &request) {
+    ForEach([&request](const TypeMatcher &matcher, const ValueSP &value) {
+      request.TryCompleteCurrentArg(matcher.GetMatchString().GetStringRef());
+      return true;
+    });
+  }
+
 protected:
   FormattersContainer(const FormattersContainer &) = delete;
   const FormattersContainer &operator=(const FormattersContainer &) = delete;

diff  --git a/lldb/source/Commands/CommandObjectType.cpp 
b/lldb/source/Commands/CommandObjectType.cpp
index d820e7abd21f..004c066b57aa 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -37,6 +37,9 @@
 #include <functional>
 #include <memory>
 
+#define CHECK_FORMATTER_KIND_MASK(VAL)                                         
\
+  ((m_formatter_kind_mask & (VAL)) == (VAL))
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -777,6 +780,39 @@ class CommandObjectTypeFormatterDelete : public 
CommandObjectParsed {
 
   ~CommandObjectTypeFormatterDelete() override = default;
 
+  void
+  HandleArgumentCompletion(CompletionRequest &request,
+                           OptionElementVector &opt_element_vector) override {
+    if (request.GetCursorIndex())
+      return;
+
+    DataVisualization::Categories::ForEach(
+        [this, &request](const lldb::TypeCategoryImplSP &category_sp) {
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemValue))
+            category_sp->GetTypeFormatsContainer()->AutoComplete(request);
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexValue))
+            category_sp->GetRegexTypeFormatsContainer()->AutoComplete(request);
+
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemSummary))
+            category_sp->GetTypeSummariesContainer()->AutoComplete(request);
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexSummary))
+            category_sp->GetRegexTypeSummariesContainer()->AutoComplete(
+                request);
+
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemFilter))
+            category_sp->GetTypeFiltersContainer()->AutoComplete(request);
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexFilter))
+            category_sp->GetRegexTypeFiltersContainer()->AutoComplete(request);
+
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemSynth))
+            category_sp->GetTypeSyntheticsContainer()->AutoComplete(request);
+          if (CHECK_FORMATTER_KIND_MASK(eFormatCategoryItemRegexSynth))
+            category_sp->GetRegexTypeSyntheticsContainer()->AutoComplete(
+                request);
+          return true;
+        });
+  }
+
 protected:
   virtual bool FormatterSpecificDeletion(ConstString typeCS) { return false; }
 

diff  --git a/lldb/test/API/functionalities/completion/TestCompletion.py 
b/lldb/test/API/functionalities/completion/TestCompletion.py
index befa1dbc2b58..4e78b6e23730 100644
--- a/lldb/test/API/functionalities/completion/TestCompletion.py
+++ b/lldb/test/API/functionalities/completion/TestCompletion.py
@@ -581,6 +581,27 @@ def test_symbol_name(self):
         # (anonymous namespace)::Quux().
         self.complete_from_to('breakpoint set -n Qu', '')
 
+    def test_completion_type_formatter_delete(self):
+        self.runCmd('type filter add --child a Aoo')
+        self.complete_from_to('type filter delete ', ['Aoo'])
+        self.runCmd('type filter add --child b -x Boo')
+        self.complete_from_to('type filter delete ', ['Boo'])
+
+        self.runCmd('type format add -f hex Coo')
+        self.complete_from_to('type format delete ', ['Coo'])
+        self.runCmd('type format add -f hex -x Doo')
+        self.complete_from_to('type format delete ', ['Doo'])
+
+        self.runCmd('type summary add -c Eoo')
+        self.complete_from_to('type summary delete ', ['Eoo'])
+        self.runCmd('type summary add -x -c Foo')
+        self.complete_from_to('type summary delete ', ['Foo'])
+
+        self.runCmd('type synthetic add Goo -l test')
+        self.complete_from_to('type synthetic delete ', ['Goo'])
+        self.runCmd('type synthetic add -x Hoo -l test')
+        self.complete_from_to('type synthetic delete ', ['Hoo'])
+
     @skipIf(archs=no_match(['x86_64']))
     def test_register_read_and_write_on_x86(self):
         """Test the completion of the commands register read and write on 
x86"""


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to