[PATCH] D108556: [clangd] Don't highlight ObjC `id` and `instancetype`

David Goldman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 23 07:32:54 PDT 2021


dgoldman created this revision.
dgoldman added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
dgoldman requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Even though they're implemented via typedefs, we typically
want to treat them like keywords (default editor behavior).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108556

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -661,13 +661,15 @@
         @interface $Class_decl[[Foo]]
         @end
         @interface $Class_decl[[Bar]] : $Class[[Foo]]
-        -($Class[[id]]) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]];
+        -(id) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]];
+        +(instancetype)$StaticMethod_decl_static[[sharedInstance]];
         +(void) $StaticMethod_decl_static[[explode]];
         @end
         @implementation $Class_decl[[Bar]]
-        -($Class[[id]]) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]] {
+        -(id) $Method_decl[[x]]:(int)$Parameter_decl[[a]] $Method_decl[[y]]:(int)$Parameter_decl[[b]] {
           return self;
         }
+        +(instancetype)$StaticMethod_decl_static[[sharedInstance]] { return 0; }
         +(void) $StaticMethod_decl_static[[explode]] {}
         @end
 
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -78,6 +78,12 @@
       D = Templated;
   }
   if (auto *TD = dyn_cast<TypedefNameDecl>(D)) {
+    // Even though ObjC `id` and `instancetype` are implemented via typedefs, we
+    // don't want to treat them like typedefs - instead let the editor treat
+    // them like keywords.
+    if (TD == D->getASTContext().getObjCInstanceTypeDecl() ||
+        TD == D->getASTContext().getObjCIdDecl())
+      return llvm::None;
     // We try to highlight typedefs as their underlying type.
     if (auto K =
             kindForType(TD->getUnderlyingType().getTypePtrOrNull(), Resolver))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108556.368102.patch
Type: text/x-patch
Size: 2036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210823/f9af1a3f/attachment.bin>


More information about the cfe-commits mailing list