diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -414,12 +414,12 @@ static std::string getLocalScope(const Decl *D) { std::vector Scopes; const DeclContext *DC = D->getDeclContext(); - auto GetName = [](const Decl *D) { - const NamedDecl *ND = dyn_cast(D); - std::string Name = ND->getNameAsString(); - // FIXME(sammccall): include template params/specialization args?. - if (!Name.empty()) - return Name; + auto GetName = [](const TypeDecl *D) { + if (!D->getDeclName().isEmpty()) { + PrintingPolicy Policy = D->getASTContext().getPrintingPolicy(); + Policy.SuppressScope = true; + return declaredType(D).getAsString(Policy); + } if (auto RD = dyn_cast(D)) return ("(anonymous " + RD->getKindName() + ")").str(); return std::string(""); diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp --- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -910,13 +910,13 @@ }}, // Constructor of partially-specialized class template {R"cpp( - template struct X; + template struct X; template struct X{ [[^X]](); }; )cpp", [](HoverInfo &HI) { HI.NamespaceScope = ""; HI.Name = "X"; - HI.LocalScope = "X::"; // FIXME: Should be X:: + HI.LocalScope = "X::"; // FIXME: X:: HI.Kind = SymbolKind::Constructor; HI.ReturnType = "X"; HI.Definition = "X()"; @@ -1029,8 +1029,8 @@ HI.Type = "enum Color"; HI.Value = "1"; }}, - // FIXME: We should use the Decl referenced, even if it comes from an - // implicit instantiation. + // FIXME: We should use the Decl referenced, even if from an implicit + // instantiation. Then the scope would be Add<1, 2> and the value 3. {R"cpp( template struct Add { static constexpr int result = a + b; @@ -1043,7 +1043,7 @@ HI.Kind = SymbolKind::Property; HI.Type = "const int"; HI.NamespaceScope = ""; - HI.LocalScope = "Add::"; + HI.LocalScope = "Add::"; }}, {R"cpp( const char *[[ba^r]] = "1234";