[PATCH] D96612: [clangd] Improve printing of Objective-C categories and methods

David Goldman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 12:20:29 PST 2021


dgoldman updated this revision to Diff 323443.
dgoldman added a comment.

- Add class method test case + swap to auto


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96612/new/

https://reviews.llvm.org/D96612

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -848,6 +848,42 @@
                 SymRange(Main.range("forwardfunc")))));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+      $Cat[[@interface Cat
+      + (id)sharedCat;
+      @end]]
+      $SneakyCat[[@interface Cat (Sneaky)
+      - (id)sneak:(id)behavior;
+      @end]]
+
+      $MeowCat[[@interface Cat ()
+      - (void)meow;
+      @end]]
+      $PurCat[[@interface Cat ()
+      - (void)pur;
+      @end]]
+    )cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+      getSymbols(TU.build()),
+      ElementsAre(
+          AllOf(WithName("Cat"), SymRange(Main.range("Cat")),
+                Children(AllOf(WithName("+sharedCat"),
+                               WithKind(SymbolKind::Method)))),
+          AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
+                Children(
+                    AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method)))),
+          AllOf(
+              WithName("Cat()"), SymRange(Main.range("MeowCat")),
+              Children(AllOf(WithName("-meow"), WithKind(SymbolKind::Method)))),
+          AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
+                Children(
+                    AllOf(WithName("-pur"), WithKind(SymbolKind::Method))))));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/AST.cpp
===================================================================
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -221,6 +221,14 @@
     return Out.str();
   }
 
+  if (const auto *C = dyn_cast<ObjCContainerDecl>(&ND))
+    return printObjCContainer(*C);
+  if (const auto *Method = dyn_cast<ObjCMethodDecl>(&ND)) {
+    Out << (Method->isInstanceMethod() ? '-' : '+');
+    Method->getSelector().print(Out);
+    return Out.str();
+  }
+
   if (isAnonymous(ND.getDeclName())) {
     // Come up with a presentation for an anonymous entity.
     if (isa<NamespaceDecl>(ND))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96612.323443.patch
Type: text/x-patch
Size: 2330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210212/159b80fb/attachment-0001.bin>


More information about the cfe-commits mailing list