[PATCH] D130265: [clangd] resolve forwarded parameters in Hover

Tobias Ribizel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 21 06:09:43 PDT 2022


upsj created this revision.
upsj added reviewers: sammccall, kadircet.
upsj added a project: clang-tools-extra.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
upsj requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

This uses `resolveForwardedParameters` to get parameter names in Hover. The patch currently produces a slight inconsistency, since the definition uses the original function decl, while the parameters are resolved correctly.
I could use some feedback on how this should be handled - maybe add a comment in the style of "This function involves forwarding" that explains why the parameter names don't match?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130265

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -263,6 +263,29 @@
              {{"bool"}, std::string("T"), std::string("false")},
          };
        }},
+      // Forwarding function decl
+      {R"cpp(
+          void baz(int a);
+          template <typename... Args>
+          void foo(Args... args) {
+            baz(args...);
+          }
+
+          void bar() {
+            [[fo^o]](3);
+          }
+          )cpp",
+       [](HoverInfo &HI) {
+         HI.NamespaceScope = "";
+         HI.Name = "foo";
+         HI.Kind = index::SymbolKind::Function;
+         HI.Definition = "template <> void foo << int >> (int args)";
+         HI.ReturnType = "void";
+         HI.Type = "void (int)";
+         HI.Parameters = {
+             {{"int"}, std::string("a"), llvm::None},
+         };
+       }},
       // Pointers to lambdas
       {R"cpp(
         void foo() {
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -369,7 +369,7 @@
                                const FunctionDecl *FD,
                                const PrintingPolicy &PP) {
   HI.Parameters.emplace();
-  for (const ParmVarDecl *PVD : FD->parameters())
+  for (const ParmVarDecl *PVD : resolveForwardingParameters(FD))
     HI.Parameters->emplace_back(toHoverInfoParam(PVD, PP));
 
   // We don't want any type info, if name already contains it. This is true for
@@ -385,7 +385,6 @@
   if (const VarDecl *VD = llvm::dyn_cast<VarDecl>(D)) // Lambdas
     QT = VD->getType().getDesugaredType(D->getASTContext());
   HI.Type = printType(QT, D->getASTContext(), PP);
-  // FIXME: handle variadics.
 }
 
 // Non-negative numbers are printed using min digits


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130265.446461.patch
Type: text/x-patch
Size: 1976 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220721/820f15ef/attachment.bin>


More information about the cfe-commits mailing list