Skip to content

Commit e51484a

Browse files
committed
[clangd] Fix hover 'local scope' to include class template params
Summary: Fixes the last part of clangd/clangd#76 Reviewers: kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70325
1 parent bb7c8e9 commit e51484a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ static PrintingPolicy printingPolicyForDecls(PrintingPolicy Base) {
414414
static std::string getLocalScope(const Decl *D) {
415415
std::vector<std::string> Scopes;
416416
const DeclContext *DC = D->getDeclContext();
417-
auto GetName = [](const Decl *D) {
418-
const NamedDecl *ND = dyn_cast<NamedDecl>(D);
419-
std::string Name = ND->getNameAsString();
420-
// FIXME(sammccall): include template params/specialization args?.
421-
if (!Name.empty())
422-
return Name;
417+
auto GetName = [](const TypeDecl *D) {
418+
if (!D->getDeclName().isEmpty()) {
419+
PrintingPolicy Policy = D->getASTContext().getPrintingPolicy();
420+
Policy.SuppressScope = true;
421+
return declaredType(D).getAsString(Policy);
422+
}
423423
if (auto RD = dyn_cast<RecordDecl>(D))
424424
return ("(anonymous " + RD->getKindName() + ")").str();
425425
return std::string("");

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,13 +910,13 @@ void foo())cpp";
910910
}},
911911
// Constructor of partially-specialized class template
912912
{R"cpp(
913-
template<typename> struct X;
913+
template<typename, typename=void> struct X;
914914
template<typename T> struct X<T*>{ [[^X]](); };
915915
)cpp",
916916
[](HoverInfo &HI) {
917917
HI.NamespaceScope = "";
918918
HI.Name = "X";
919-
HI.LocalScope = "X::"; // FIXME: Should be X<T *>::
919+
HI.LocalScope = "X<T *>::"; // FIXME: X<T *, void>::
920920
HI.Kind = SymbolKind::Constructor;
921921
HI.ReturnType = "X<T *>";
922922
HI.Definition = "X()";
@@ -1029,8 +1029,8 @@ void foo())cpp";
10291029
HI.Type = "enum Color";
10301030
HI.Value = "1";
10311031
}},
1032-
// FIXME: We should use the Decl referenced, even if it comes from an
1033-
// implicit instantiation.
1032+
// FIXME: We should use the Decl referenced, even if from an implicit
1033+
// instantiation. Then the scope would be Add<1, 2> and the value 3.
10341034
{R"cpp(
10351035
template<int a, int b> struct Add {
10361036
static constexpr int result = a + b;
@@ -1043,7 +1043,7 @@ void foo())cpp";
10431043
HI.Kind = SymbolKind::Property;
10441044
HI.Type = "const int";
10451045
HI.NamespaceScope = "";
1046-
HI.LocalScope = "Add::";
1046+
HI.LocalScope = "Add<a, b>::";
10471047
}},
10481048
{R"cpp(
10491049
const char *[[ba^r]] = "1234";

0 commit comments

Comments
 (0)