[clang-tools-extra] 5b0022a - [clangd] Support UnresolvedUsingTypeLoc AST node in FindTarget.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri May 20 05:54:30 PDT 2022
Author: Haojian Wu
Date: 2022-05-20T14:54:17+02:00
New Revision: 5b0022a9df3f3a35661f71b23a66c667e8501c32
URL: https://github.com/llvm/llvm-project/commit/5b0022a9df3f3a35661f71b23a66c667e8501c32
DIFF: https://github.com/llvm/llvm-project/commit/5b0022a9df3f3a35661f71b23a66c667e8501c32.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index dcdac55c26b70..4085915890513 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -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 @@ struct TargetFinder {
}
}
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 @@ struct TargetFinder {
// 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())
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index f7d547bd960cd..51eae572ed904 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -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) {
More information about the cfe-commits
mailing list