forked from OSchip/llvm-project
[clangd] Find definition of ClassTemplate without going through index.
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. Differential Revision: https://reviews.llvm.org/D113029
This commit is contained in:
parent
2aec2549e8
commit
97fbc975fa
|
@ -80,6 +80,9 @@ const NamedDecl *getDefinition(const NamedDecl *D) {
|
|||
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;
|
||||
|
|
|
@ -675,7 +675,7 @@ TEST(LocateSymbol, All) {
|
|||
|
||||
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 @@ TEST(LocateSymbol, All) {
|
|||
|
||||
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",
|
||||
|
|
Loading…
Reference in New Issue