diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -274,11 +274,13 @@ dyn_cast(D)) { // Objective-C implementation should map back to its interface. D = IID->getClassInterface(); + Flags |= Rel::Underlying; } else if (const ObjCCategoryImplDecl *CID = dyn_cast(D)) { // Objective-C category implementation should map back to its category // declaration. D = CID->getCategoryDecl(); + Flags |= Rel::Underlying; } if (const Decl *Pat = getTemplatePattern(D)) { @@ -288,6 +290,8 @@ Flags |= Rel::TemplateInstantiation; } + if (!D) + return; report(D, Flags); } diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -614,7 +614,7 @@ @implementation [[Foo]] @end )cpp"; - EXPECT_DECLS("ObjCImplementationDecl", "@interface Foo"); + EXPECT_DECLS("ObjCImplementationDecl", {"@interface Foo", Rel::Underlying}); Code = R"cpp( @interface Foo @@ -624,7 +624,8 @@ @implementation [[Foo]] (Ext) @end )cpp"; - EXPECT_DECLS("ObjCCategoryImplDecl", "@interface Foo(Ext)"); + EXPECT_DECLS("ObjCCategoryImplDecl", + {"@interface Foo(Ext)", Rel::Underlying}); Code = R"cpp( @protocol Foo diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -542,6 +542,29 @@ // Figure out why it's platform-dependent. } +TEST_F(SymbolCollectorTest, ObjCLocations) { + Annotations Header(R"( + // Declared in header, defined in main. + @interface $dogdecl[[Dog]] + @end + @interface $fluffydecl[[Dog]] (Fluffy) + @end + )"); + Annotations Main(R"( + @implementation $dogdef[[Dog]] + @end + @implementation $fluffydef[[Dog]] (Fluffy) + @end + )"); + runSymbolCollector(Header.code(), Main.code(), {"-xobjective-c++"}); + EXPECT_THAT(Symbols, + UnorderedElementsAre( + AllOf(QName("Dog"), DeclRange(Header.range("dogdecl")), + DefRange(Main.range("dogdef"))), + AllOf(QName("Fluffy"), DeclRange(Header.range("fluffydecl")), + DefRange(Main.range("fluffydef"))))); +} + TEST_F(SymbolCollectorTest, Locations) { Annotations Header(R"cpp( // Declared in header, defined in main.