adamcz created this revision. adamcz added a reviewer: kadircet. Herald added subscribers: usaxena95, arphaman. adamcz requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
I noticed that, while go-to-def works on cases like: namespace ns { template<typename T> struct Foo {}; } using ::ns::Fo^o; it only works because of the FileIndex. We can get definition location directly from AST too. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D113029 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 @@ -675,7 +675,7 @@ R"cpp(// Declaration of explicit template specialization template <typename T> - struct $decl[[Foo]] {}; + struct $decl[[$def[[Foo]]]] {}; template <> struct Fo^o<int> {}; @@ -683,12 +683,25 @@ R"cpp(// Declaration of partial template specialization template <typename T> - struct $decl[[Foo]] {}; + struct $decl[[$def[[Foo]]]] {}; template <typename T> struct Fo^o<T*> {}; )cpp", + R"cpp(// Definition on ClassTemplateDecl + namespace ns { + // Forward declaration. + template<typename T> + struct $decl[[Foo]]; + + template <typename T> + struct $def[[Foo]] {}; + } + + using ::ns::Fo^o; + )cpp", + R"cpp(// auto builtin type (not supported) ^auto x = 42; )cpp", Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -80,6 +80,9 @@ return VD->getDefinition(); if (const auto *FD = dyn_cast<FunctionDecl>(D)) return FD->getDefinition(); + if (const auto *CTD = dyn_cast<ClassTemplateDecl>(D)) + if (const auto *RD = CTD->getTemplatedDecl()) + return RD->getDefinition(); // Objective-C classes can have three types of declarations: // // - forward declaration: @class MyClass;
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -675,7 +675,7 @@ R"cpp(// Declaration of explicit template specialization template <typename T> - struct $decl[[Foo]] {}; + struct $decl[[$def[[Foo]]]] {}; template <> struct Fo^o<int> {}; @@ -683,12 +683,25 @@ R"cpp(// Declaration of partial template specialization template <typename T> - struct $decl[[Foo]] {}; + struct $decl[[$def[[Foo]]]] {}; template <typename T> struct Fo^o<T*> {}; )cpp", + R"cpp(// Definition on ClassTemplateDecl + namespace ns { + // Forward declaration. + template<typename T> + struct $decl[[Foo]]; + + template <typename T> + struct $def[[Foo]] {}; + } + + using ::ns::Fo^o; + )cpp", + R"cpp(// auto builtin type (not supported) ^auto x = 42; )cpp", Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -80,6 +80,9 @@ return VD->getDefinition(); if (const auto *FD = dyn_cast<FunctionDecl>(D)) return FD->getDefinition(); + if (const auto *CTD = dyn_cast<ClassTemplateDecl>(D)) + if (const auto *RD = CTD->getTemplatedDecl()) + return RD->getDefinition(); // Objective-C classes can have three types of declarations: // // - forward declaration: @class MyClass;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits