This revision was automatically updated to reflect the committed changes. Closed by commit rG8401713b3ef1: [clangd] Ignore ObjC `id` and `instancetype` in FindTarget (authored by dgoldman).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D108556/new/ https://reviews.llvm.org/D108556 Files: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/FindTargetTests.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/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -995,6 +995,20 @@ } )cpp"; EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance"); + + Code = R"cpp( + @interface Foo + + ([[id]])sharedInstance; + @end + )cpp"; + EXPECT_DECLS("TypedefTypeLoc"); + + Code = R"cpp( + @interface Foo + + ([[instancetype]])sharedInstance; + @end + )cpp"; + EXPECT_DECLS("TypedefTypeLoc"); } class FindExplicitReferencesTest : public ::testing::Test { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -94,6 +94,16 @@ return nullptr; } +// Returns true if the `TypedefNameDecl` should not be reported. +bool shouldSkipTypedef(const TypedefNameDecl *TD) { + // These should be treated as keywords rather than decls - the typedef is an + // odd implementation detail. + if (TD == TD->getASTContext().getObjCInstanceTypeDecl() || + TD == TD->getASTContext().getObjCIdDecl()) + return true; + return false; +} + // TargetFinder locates the entities that an AST node refers to. // // Typically this is (possibly) one declaration and (possibly) one type, but @@ -395,6 +405,8 @@ } } void VisitTypedefType(const TypedefType *TT) { + if (shouldSkipTypedef(TT->getDecl())) + return; Outer.add(TT->getDecl(), Flags); } void @@ -903,6 +915,8 @@ } void VisitTypedefTypeLoc(TypedefTypeLoc L) { + if (shouldSkipTypedef(L.getTypedefNameDecl())) + return; Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), /*IsDecl=*/false,
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/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -995,6 +995,20 @@ } )cpp"; EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance"); + + Code = R"cpp( + @interface Foo + + ([[id]])sharedInstance; + @end + )cpp"; + EXPECT_DECLS("TypedefTypeLoc"); + + Code = R"cpp( + @interface Foo + + ([[instancetype]])sharedInstance; + @end + )cpp"; + EXPECT_DECLS("TypedefTypeLoc"); } class FindExplicitReferencesTest : public ::testing::Test { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -94,6 +94,16 @@ return nullptr; } +// Returns true if the `TypedefNameDecl` should not be reported. +bool shouldSkipTypedef(const TypedefNameDecl *TD) { + // These should be treated as keywords rather than decls - the typedef is an + // odd implementation detail. + if (TD == TD->getASTContext().getObjCInstanceTypeDecl() || + TD == TD->getASTContext().getObjCIdDecl()) + return true; + return false; +} + // TargetFinder locates the entities that an AST node refers to. // // Typically this is (possibly) one declaration and (possibly) one type, but @@ -395,6 +405,8 @@ } } void VisitTypedefType(const TypedefType *TT) { + if (shouldSkipTypedef(TT->getDecl())) + return; Outer.add(TT->getDecl(), Flags); } void @@ -903,6 +915,8 @@ } void VisitTypedefTypeLoc(TypedefTypeLoc L) { + if (shouldSkipTypedef(L.getTypedefNameDecl())) + return; Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), L.getNameLoc(), /*IsDecl=*/false,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits