[PATCH] D83501: [clangd][ObjC] Improve xrefs for protocols and classes

David Goldman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 10 10:47:41 PDT 2020


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

Find target fixes + symbol collector test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83501

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp


Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -542,6 +542,29 @@
   //        Figure out why it's platform-dependent.
 }
 
+TEST_F(SymbolCollectorTest, ObjCLocations) {
+  Annotations Header(R"(
+    // Declared in header, defined in main.
+    @interface $dogdecl[[Dog]]
+    @end
+    @interface $fluffydecl[[Dog]] (Fluffy)
+    @end
+  )");
+  Annotations Main(R"(
+    @implementation $dogdef[[Dog]]
+    @end
+    @implementation $fluffydef[[Dog]] (Fluffy)
+    @end
+  )");
+  runSymbolCollector(Header.code(), Main.code(), {"-xobjective-c++"});
+  EXPECT_THAT(Symbols,
+              UnorderedElementsAre(
+                  AllOf(QName("Dog"), DeclRange(Header.range("dogdecl")),
+                        DefRange(Main.range("dogdef"))),
+                  AllOf(QName("Fluffy"), DeclRange(Header.range("fluffydecl")),
+                        DefRange(Main.range("fluffydef")))));
+}
+
 TEST_F(SymbolCollectorTest, Locations) {
   Annotations Header(R"cpp(
     // Declared in header, defined in main.
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -614,7 +614,7 @@
     @implementation [[Foo]]
     @end
   )cpp";
-  EXPECT_DECLS("ObjCImplementationDecl", "@interface Foo");
+  EXPECT_DECLS("ObjCImplementationDecl", {"@interface Foo", Rel::Underlying});
 
   Code = R"cpp(
     @interface Foo
@@ -624,7 +624,8 @@
     @implementation [[Foo]] (Ext)
     @end
   )cpp";
-  EXPECT_DECLS("ObjCCategoryImplDecl", "@interface Foo(Ext)");
+  EXPECT_DECLS("ObjCCategoryImplDecl",
+               {"@interface Foo(Ext)", Rel::Underlying});
 
   Code = R"cpp(
     @protocol Foo
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -274,11 +274,13 @@
                    dyn_cast<ObjCImplementationDecl>(D)) {
       // Objective-C implementation should map back to its interface.
       D = IID->getClassInterface();
+      Flags |= Rel::Underlying;
     } else if (const ObjCCategoryImplDecl *CID =
                    dyn_cast<ObjCCategoryImplDecl>(D)) {
       // Objective-C category implementation should map back to its category
       // declaration.
       D = CID->getCategoryDecl();
+      Flags |= Rel::Underlying;
     }
 
     if (const Decl *Pat = getTemplatePattern(D)) {
@@ -288,6 +290,8 @@
       Flags |= Rel::TemplateInstantiation;
     }
 
+    if (!D)
+      return;
     report(D, Flags);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83501.277100.patch
Type: text/x-patch
Size: 2896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200710/333d69be/attachment.bin>


More information about the cfe-commits mailing list