[PATCH] D152720: [clangd][ObjC] Support ObjC class rename from implementation decls

David Goldman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 12 14:17:00 PDT 2023


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

Run clang format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152720

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


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -840,6 +840,16 @@
           foo('x');
         }
       )cpp",
+
+      // ObjC class.
+      R"cpp(
+        @interface [[Fo^o]]
+        @end
+        @implementation [[F^oo]]
+        @end
+
+        void func([[Foo]] *f) {}
+      )cpp",
   };
   llvm::StringRef NewName = "NewName";
   for (llvm::StringRef T : Tests) {
@@ -1468,7 +1478,7 @@
 
 TEST(CrossFileRenameTests, WithUpToDateIndex) {
   MockCompilationDatabase CDB;
-  CDB.ExtraClangFlags = {"-xc++"};
+  CDB.ExtraClangFlags = {"-xobjective-c++"};
   // rename is runnning on all "^" points in FooH, and "[[]]" ranges are the
   // expected rename occurrences.
   struct Case {
@@ -1557,13 +1567,12 @@
         }
       )cpp",
       },
-      {
-          // virtual templated method
-          R"cpp(
+      {// virtual templated method
+       R"cpp(
         template <typename> class Foo { virtual void [[m]](); };
         class Bar : Foo<int> { void [[^m]]() override; };
       )cpp",
-          R"cpp(
+       R"cpp(
           #include "foo.h"
 
           template<typename T> void Foo<T>::[[m]]() {}
@@ -1571,8 +1580,7 @@
           // the canonical Foo<T>::m().
           // https://github.com/clangd/clangd/issues/1325
           class Baz : Foo<float> { void m() override; };
-        )cpp"
-      },
+        )cpp"},
       {
           // rename on constructor and destructor.
           R"cpp(
@@ -1677,6 +1685,20 @@
         }
       )cpp",
       },
+      {
+          // Objective-C classes.
+          R"cpp(
+        @interface [[Fo^o]]
+        @end
+      )cpp",
+          R"cpp(
+        #include "foo.h"
+        @implementation [[F^oo]]
+        @end
+
+        void func([[Foo]] *f) {}
+      )cpp",
+      },
   };
 
   trace::TestTracer Tracer;
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -707,6 +707,14 @@
                                   /*IsDecl=*/true,
                                   {OCID->getCategoryDecl()}});
     }
+
+    void VisitObjCImplementationDecl(const ObjCImplementationDecl *OIMD) {
+      if (const auto *CI = OIMD->getClassInterface())
+        Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+                                    OIMD->getLocation(),
+                                    /*IsDecl=*/true,
+                                    {CI}});
+    }
   };
 
   Visitor V{Resolver};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152720.530665.patch
Type: text/x-patch
Size: 2722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230612/13c2bae7/attachment-0001.bin>


More information about the cfe-commits mailing list