[PATCH] D70325: [clangd] Fix hover 'local scope' to include class template params

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 19 01:56:13 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe51484abd402: [clangd] Fix hover 'local scope' to include class template params (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D70325?vs=229910&id=230004#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70325/new/

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
@@ -910,13 +910,13 @@
        }},
       // Constructor of partially-specialized class template
       {R"cpp(
-          template<typename> struct X;
+          template<typename, typename=void> struct X;
           template<typename T> struct X<T*>{ [[^X]](); };
           )cpp",
        [](HoverInfo &HI) {
          HI.NamespaceScope = "";
          HI.Name = "X";
-         HI.LocalScope = "X::";        // FIXME: Should be X<T *>::
+         HI.LocalScope = "X<T *>::"; // FIXME: X<T *, void>::
          HI.Kind = SymbolKind::Constructor;
          HI.ReturnType = "X<T *>";
          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<int a, int b> 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<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("");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70325.230004.patch
Type: text/x-patch
Size: 2569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191119/4913f490/attachment.bin>


More information about the cfe-commits mailing list