[clang-tools-extra] 7bb785c - [clangd] Show parameters for construct.
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 2 21:21:12 PST 2021
Author: lh123
Date: 2021-12-03T13:20:41+08:00
New Revision: 7bb785cc339b0ea268e388c570c9a0cd78f136c8
URL: https://github.com/llvm/llvm-project/commit/7bb785cc339b0ea268e388c570c9a0cd78f136c8
DIFF: https://github.com/llvm/llvm-project/commit/7bb785cc339b0ea268e388c570c9a0cd78f136c8.diff
LOG: [clangd] Show parameters for construct.
Show parameters for construct.
Reviewed By: kadircet
Differential Revision: https://reviews.llvm.org/D114621
Added:
Modified:
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp
index faea812712ab2..76e9f4d243b95 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1058,20 +1058,24 @@ markup::Document HoverInfo::present() const {
// - `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()));
- }
+ }
+
+ 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);
}
+ // Don't print Type after Parameters or ReturnType as this will just duplicate
+ // the information
+ if (Type && !ReturnType && !Parameters)
+ Output.addParagraph().appendText("Type: ").appendCode(*Type);
+
if (Value) {
markup::Paragraph &P = Output.addParagraph();
P.appendText("Value = ");
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 79510ceefa1b3..0d71dcbf8a931 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2680,6 +2680,32 @@ public: def)",
// In cls<int>
protected: int method())",
+ },
+ {
+ [](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) {
More information about the cfe-commits
mailing list