diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -507,11 +507,11 @@ markup::Document HoverInfo::present() const { markup::Document Output; // Header contains a text of the form: - // variable `var` : `int` + // variable `var` // // class `X` // - // function `foo` → `int` + // function `foo` // Note that we are making use of a level-3 heading because VSCode renders // level 1 and 2 headers in a huge font, see // https://github.com/microsoft/vscode/issues/88417 for details. @@ -534,29 +534,33 @@ Header.appendText(index::getSymbolKindString(Kind)); Header.appendCode(Name); - if (ReturnType) { - Header.appendText("→"); - Header.appendCode(*ReturnType); - } else if (Type) { - Header.appendText(":"); - Header.appendCode(*Type); - } bool HasMiddleSection = false; // Put a linebreak after header to increase readability. Output.addRuler(); - // For functions we display signature in a list form, e.g.: - // - `bool param1` - // - `int param2 = 5` - if (Parameters && !Parameters->empty()) { + // Print Types on their own lines to reduce chances of getting line-wrapped by + // editor, as they might be long. + if (ReturnType) { HasMiddleSection = true; - 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())); + // For functions we display signature in a list form, e.g.: + // 🡺 `x` + // Parameters: + // - `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) { + HasMiddleSection = true; + Output.addParagraph().appendText("Type: ").appendCode(*Type); } if (Value) { diff --git a/clang-tools-extra/clangd/test/hover.test b/clang-tools-extra/clangd/test/hover.test --- a/clang-tools-extra/clangd/test/hover.test +++ b/clang-tools-extra/clangd/test/hover.test @@ -9,7 +9,7 @@ # CHECK-NEXT: "result": { # CHECK-NEXT: "contents": { # CHECK-NEXT: "kind": "plaintext", -# CHECK-NEXT: "value": "function foo → void\n\nvoid foo()" +# CHECK-NEXT: "value": "function foo\n\n🡺 void\n\nvoid foo()" # CHECK-NEXT: }, # CHECK-NEXT: "range": { # CHECK-NEXT: "end": { diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -1723,8 +1723,10 @@ HI.NamespaceScope = "ns::"; HI.Definition = "ret_type foo(params) {}"; }, - R"(function foo → ret_type + R"(function foo +🡺 ret_type +Parameters: - - type - type foo @@ -1742,8 +1744,9 @@ HI.Type = "type"; HI.Definition = "def"; }, - R"(variable foo : type + R"(variable foo +Type: type Value = value // In test::bar @@ -1775,10 +1778,8 @@ HoverInfo HI; HI.Kind = index::SymbolKind::Variable; HI.Name = "foo"; - HI.Type = "type"; - EXPECT_EQ(HI.present().asMarkdown(), - "### variable `foo` \\: `type` \n\n---"); + EXPECT_EQ(HI.present().asMarkdown(), "### variable `foo` \n\n---"); } } // namespace