diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -78,6 +78,12 @@ D = Templated; } if (auto *TD = dyn_cast(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)) diff --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp --- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp +++ b/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