sammccall created this revision. sammccall added a reviewer: kadircet. Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
Fixes the last part of https://github.com/clangd/clangd/issues/76 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70325 Files: clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/unittests/XRefsTests.cpp Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -916,7 +916,7 @@ [](HoverInfo &HI) { HI.NamespaceScope = ""; HI.Name = "X"; - HI.LocalScope = "X::"; // FIXME: Should be X<T *>:: + HI.LocalScope = "X<T *>::"; HI.Kind = SymbolKind::Constructor; HI.ReturnType = "X<T *>"; HI.Definition = "X()"; @@ -1019,8 +1019,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<int a, int b> struct Add { static constexpr int result = a + b; @@ -1033,7 +1033,7 @@ HI.Kind = SymbolKind::Property; HI.Type = "const int"; HI.NamespaceScope = ""; - HI.LocalScope = "Add::"; + HI.LocalScope = "Add<a, b>::"; }}, {R"cpp( const char *[[ba^r]] = "1234"; Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -414,12 +414,12 @@ static std::string getLocalScope(const Decl *D) { std::vector<std::string> Scopes; const DeclContext *DC = D->getDeclContext(); - auto GetName = [](const Decl *D) { - const NamedDecl *ND = dyn_cast<NamedDecl>(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<RecordDecl>(D)) return ("(anonymous " + RD->getKindName() + ")").str(); return std::string("");
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/XRefsTests.cpp +++ clang-tools-extra/clangd/unittests/XRefsTests.cpp @@ -916,7 +916,7 @@ [](HoverInfo &HI) { HI.NamespaceScope = ""; HI.Name = "X"; - HI.LocalScope = "X::"; // FIXME: Should be X<T *>:: + HI.LocalScope = "X<T *>::"; HI.Kind = SymbolKind::Constructor; HI.ReturnType = "X<T *>"; HI.Definition = "X()"; @@ -1019,8 +1019,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<int a, int b> struct Add { static constexpr int result = a + b; @@ -1033,7 +1033,7 @@ HI.Kind = SymbolKind::Property; HI.Type = "const int"; HI.NamespaceScope = ""; - HI.LocalScope = "Add::"; + HI.LocalScope = "Add<a, b>::"; }}, {R"cpp( const char *[[ba^r]] = "1234"; Index: clang-tools-extra/clangd/XRefs.cpp =================================================================== --- clang-tools-extra/clangd/XRefs.cpp +++ clang-tools-extra/clangd/XRefs.cpp @@ -414,12 +414,12 @@ static std::string getLocalScope(const Decl *D) { std::vector<std::string> Scopes; const DeclContext *DC = D->getDeclContext(); - auto GetName = [](const Decl *D) { - const NamedDecl *ND = dyn_cast<NamedDecl>(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<RecordDecl>(D)) return ("(anonymous " + RD->getKindName() + ")").str(); return std::string("");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits