dgoldman created this revision. dgoldman added a reviewer: sammccall. Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
Previously clangd would jump to forward declarations for protocols and classes instead of their definition/implementation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D83501 Files: clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -674,7 +674,37 @@ enum class E { [[A]], B }; E e = E::A^; }; - )cpp"}; + )cpp", + + R"objc(//objc + @protocol $decl[[Dog]]; + @protocol $def[[Dog]] + - (void)bark; + @end + id<Do^g> getDoggo() { + return 0; + } + )objc", + + R"objc(//objc + @class $decl[[Foo]]; + @interface $def[[Foo]] + @end + Fo^o * getFoo() { + return 0; + } + )objc", + + R"objc(//objc + @class $decl[[Foo]]; + @interface Foo + @end + @implementation $def[[Foo]] + @end + Fo^o * getFoo() { + return 0; + } + )objc"}; for (const char *Test : Tests) { Annotations T(Test); llvm::Optional<Range> WantDecl; @@ -689,6 +719,11 @@ TestTU TU; TU.Code = std::string(T.code()); + std::string ObjcPrefix = "//objc"; + if (strncmp(Test, ObjcPrefix.c_str(), ObjcPrefix.size()) == 0) { + TU.Filename = "TestTU.m"; + } + // FIXME: Auto-completion in a template requires disabling delayed template // parsing. TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -78,6 +78,18 @@ return VD->getDefinition(); if (const auto *FD = dyn_cast<FunctionDecl>(D)) return FD->getDefinition(); + if (const auto *PD = dyn_cast<ObjCProtocolDecl>(D)) + return PD->getDefinition(); + // Objective-C classes can have three types of declarations: + // + // - forward declaration: @class MyClass; + // - definition declaration: @interface MyClass ... @end + // - implementation: @implementation MyClass ... @end + if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { + if (const auto *IMD = ID->getImplementation()) + return IMD; + return ID->getDefinition(); + } // Only a single declaration is allowed. if (isa<ValueDecl>(D) || isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D)) // except cases above
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -674,7 +674,37 @@ enum class E { [[A]], B }; E e = E::A^; }; - )cpp"}; + )cpp", + + R"objc(//objc + @protocol $decl[[Dog]]; + @protocol $def[[Dog]] + - (void)bark; + @end + id<Do^g> getDoggo() { + return 0; + } + )objc", + + R"objc(//objc + @class $decl[[Foo]]; + @interface $def[[Foo]] + @end + Fo^o * getFoo() { + return 0; + } + )objc", + + R"objc(//objc + @class $decl[[Foo]]; + @interface Foo + @end + @implementation $def[[Foo]] + @end + Fo^o * getFoo() { + return 0; + } + )objc"}; for (const char *Test : Tests) { Annotations T(Test); llvm::Optional<Range> WantDecl; @@ -689,6 +719,11 @@ TestTU TU; TU.Code = std::string(T.code()); + std::string ObjcPrefix = "//objc"; + if (strncmp(Test, ObjcPrefix.c_str(), ObjcPrefix.size()) == 0) { + TU.Filename = "TestTU.m"; + } + // FIXME: Auto-completion in a template requires disabling delayed template // parsing. TU.ExtraArgs.push_back("-fno-delayed-template-parsing"); Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -78,6 +78,18 @@ return VD->getDefinition(); if (const auto *FD = dyn_cast<FunctionDecl>(D)) return FD->getDefinition(); + if (const auto *PD = dyn_cast<ObjCProtocolDecl>(D)) + return PD->getDefinition(); + // Objective-C classes can have three types of declarations: + // + // - forward declaration: @class MyClass; + // - definition declaration: @interface MyClass ... @end + // - implementation: @implementation MyClass ... @end + if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { + if (const auto *IMD = ID->getImplementation()) + return IMD; + return ID->getDefinition(); + } // Only a single declaration is allowed. if (isa<ValueDecl>(D) || isa<TemplateTypeParmDecl>(D) || isa<TemplateTemplateParmDecl>(D)) // except cases above
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits