[clang-tools-extra] 159dd44 - [clangd][ObjC] Highlight Objc Ivar refs

David Goldman via cfe-commits cfe-commits at lists.llvm.org
Thu May 6 08:42:31 PDT 2021


Author: David Goldman
Date: 2021-05-06T11:41:49-04:00
New Revision: 159dd447fe98f558879343d660b5bfe90779609f

URL: https://github.com/llvm/llvm-project/commit/159dd447fe98f558879343d660b5bfe90779609f
DIFF: https://github.com/llvm/llvm-project/commit/159dd447fe98f558879343d660b5bfe90779609f.diff

LOG: [clangd][ObjC] Highlight Objc Ivar refs

Treat them just like we do for properties - as a `property` semantic
token although ideally we could differentiate the two.

Differential Revision: https://reviews.llvm.org/D101785

Added: 
    

Modified: 
    clang-tools-extra/clangd/FindTarget.cpp
    clang-tools-extra/clangd/unittests/FindTargetTests.cpp
    clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index d4cb2fe79111..4789d28ecf48 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -780,6 +780,13 @@ llvm::SmallVector<ReferenceLoc> refInStmt(const Stmt *S,
           explicitReferenceTargets(DynTypedNode::create(*E), {}, Resolver)});
     }
 
+    void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE) {
+      Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+                                  OIRE->getLocation(),
+                                  /*IsDecl=*/false,
+                                  {OIRE->getDecl()}});
+    }
+
     void VisitObjCMessageExpr(const ObjCMessageExpr *E) {
       // The name may have several tokens, we can only report the first.
       Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index f32081ac472c..beca7c292583 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -1607,6 +1607,21 @@ TEST_F(FindExplicitReferencesTest, All) {
            "5: targets = {t}, decl\n"
            "6: targets = {t}\n"
            "7: targets = {}\n"},
+       // Objective-C: instance variables
+       {
+           R"cpp(
+            @interface I {
+            @public
+              I *_z;
+            }
+            @end
+            I *f;
+            void foo() {
+              $0^f->$1^_z = 0;
+            }
+          )cpp",
+           "0: targets = {f}\n"
+           "1: targets = {I::_z}\n"},
        // Objective-C: properties
        {
            R"cpp(

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 815ef92c932e..a2e8f797ad28 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -687,6 +687,21 @@ sizeof...($TemplateParameter[[Elements]]);
         @implementation $Class[[Foo]]($Namespace_decl[[Bar]])
         @end
       )cpp",
+      R"cpp(
+        // ObjC: Properties and Ivars.
+        @interface $Class_decl[[Foo]] {
+          int $Field_decl[[_someProperty]];
+        }
+        @property(nonatomic, assign) int $Field_decl[[someProperty]];
+        @end
+        @implementation $Class_decl[[Foo]]
+        @synthesize someProperty = _someProperty;
+        - (int)$Method_decl[[doSomething]] {
+          self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+          self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
+        }
+        @end
+      )cpp",
       // Member imported from dependent base
       R"cpp(
         template <typename> struct $Class_decl[[Base]] {


        


More information about the cfe-commits mailing list