[PATCH] D114621: [clangd] Show parameters for construct.

liu hui via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 26 02:49:16 PST 2021


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

Show parameters for construct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114621

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
@@ -2683,6 +2683,32 @@
       },
       {
           [](HoverInfo &HI) {
+            HI.Definition = "cls(int a, int b = 5)";
+            HI.AccessSpecifier = "public";
+            HI.Kind = index::SymbolKind::Constructor;
+            HI.NamespaceScope = "";
+            HI.LocalScope = "cls";
+            HI.Name = "cls";
+            HI.Parameters.emplace();
+            HI.Parameters->emplace_back();
+            HI.Parameters->back().Type = "int";
+            HI.Parameters->back().Name = "a";
+            HI.Parameters->emplace_back();
+            HI.Parameters->back().Type = "int";
+            HI.Parameters->back().Name = "b";
+            HI.Parameters->back().Default = "5";
+          },
+          R"(constructor cls
+
+Parameters:
+- int a
+- int b = 5
+
+// In cls
+public: cls(int a, int b = 5))",
+      },
+      {
+          [](HoverInfo &HI) {
             HI.Kind = index::SymbolKind::Union;
             HI.AccessSpecifier = "private";
             HI.Name = "foo";
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,21 @@
     // - `bool param1`
     // - `int param2 = 5`
     Output.addParagraph().appendText("→ ").appendCode(*ReturnType);
-    if (Parameters && !Parameters->empty()) {
-      Output.addParagraph().appendText("Parameters: ");
-      markup::BulletList &L = Output.addBulletList();
-      for (const auto &Param : *Parameters) {
-        std::string Buffer;
-        llvm::raw_string_ostream OS(Buffer);
-        OS << Param;
-        L.addItem().addParagraph().appendCode(std::move(OS.str()));
-      }
-    }
   } else if (Type) {
     Output.addParagraph().appendText("Type: ").appendCode(*Type);
   }
 
+  if (Parameters && !Parameters->empty()) {
+    Output.addParagraph().appendText("Parameters: ");
+    markup::BulletList &L = Output.addBulletList();
+    for (const auto &Param : *Parameters) {
+      std::string Buffer;
+      llvm::raw_string_ostream OS(Buffer);
+      OS << Param;
+      L.addItem().addParagraph().appendCode(std::move(OS.str()));
+    }
+  }
+
   if (Value) {
     markup::Paragraph &P = Output.addParagraph();
     P.appendText("Value = ");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114621.389966.patch
Type: text/x-patch
Size: 2518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211126/560cdf5d/attachment.bin>


More information about the cfe-commits mailing list