[clangd] Support UnresolvedUsingTypeLoc AST node in FindTarget.

to make features like hover, go-to-def work when the cursor is on the
UnresolvedUsingTypeLoc.

Differential Revision: https://reviews.llvm.org/D125684
This commit is contained in:
Haojian Wu 2022-05-16 14:46:09 +02:00
parent 534ea8bca5
commit 5b0022a9df
2 changed files with 18 additions and 5 deletions

View File

@ -127,11 +127,6 @@ bool shouldSkipTypedef(const TypedefNameDecl *TD) {
// template<class X> using pvec = vector<x*>; pvec<int> x;
// There's no Decl `pvec<int>`, we must choose `pvec<X>` or `vector<int*>`
// and both are lossy. We must know upfront what the caller ultimately wants.
//
// FIXME: improve common dependent scope using name lookup in primary templates.
// We currently handle several dependent constructs, but some others remain to
// be handled:
// - UnresolvedUsingTypenameDecl
struct TargetFinder {
using RelSet = DeclRelationSet;
using Rel = DeclRelation;
@ -207,6 +202,10 @@ public:
}
}
Flags |= Rel::Alias; // continue with the alias
} else if (isa<UnresolvedUsingTypenameDecl>(D)) {
// FIXME: improve common dependent scope using name lookup in primary
// templates.
Flags |= Rel::Alias;
} else if (const UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D)) {
// Include the Introducing decl, but don't traverse it. This may end up
// including *all* shadows, which we don't want.
@ -382,6 +381,9 @@ public:
// TypeLoc never has a deduced type. https://llvm.org/PR42914
Outer.add(DT->getDeducedType(), Flags);
}
void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT) {
Outer.add(UUT->getDecl(), Flags);
}
void VisitDeducedTemplateSpecializationType(
const DeducedTemplateSpecializationType *DTST) {
if (const auto *USD = DTST->getTemplateName().getAsUsingShadowDecl())

View File

@ -268,6 +268,17 @@ TEST_F(TargetDeclTest, UsingDecl) {
EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
{"using ns::S", Rel::Alias}, {"template <typename T> class S"},
{"class S", Rel::TemplatePattern});
Code = R"cpp(
template<typename T>
class Foo { public: class foo {}; };
template <class T> class A : public Foo<T> {
using typename Foo<T>::foo;
[[foo]] abc;
};
)cpp";
EXPECT_DECLS("UnresolvedUsingTypeLoc",
{"using typename Foo<T>::foo", Rel::Alias});
}
TEST_F(TargetDeclTest, BaseSpecifier) {