[clangd] Show parameters for construct.

Show parameters for construct.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D114621
This commit is contained in:
lh123 2021-12-03 12:32:11 +08:00
parent 27ca945801
commit 7bb785cc33
2 changed files with 42 additions and 12 deletions

View File

@ -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()));
}
}
} 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()));
}
}
// 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 = ");

View File

@ -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) {