File tree 5 files changed +48
-1
lines changed
5 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,19 @@ std::string indentLines(llvm::StringRef Input) {
164
164
}
165
165
return IndentedR;
166
166
}
167
+
168
+ class Heading : public Paragraph {
169
+ public:
170
+ Heading (size_t Level) : Level(Level) {}
171
+ void renderMarkdown (llvm::raw_ostream &OS) const override {
172
+ OS << std::string (Level, ' #' ) << ' ' ;
173
+ Paragraph::renderMarkdown (OS);
174
+ }
175
+
176
+ private:
177
+ size_t Level;
178
+ };
179
+
167
180
} // namespace
168
181
169
182
std::string Block::asMarkdown () const {
@@ -278,6 +291,12 @@ BulletList &Document::addBulletList() {
278
291
Children.emplace_back (std::make_unique<BulletList>());
279
292
return *static_cast <BulletList *>(Children.back ().get ());
280
293
}
294
+
295
+ Paragraph &Document::addHeading (size_t Level) {
296
+ assert (Level > 0 );
297
+ Children.emplace_back (std::make_unique<Heading>(Level));
298
+ return *static_cast <Paragraph *>(Children.back ().get ());
299
+ }
281
300
} // namespace markup
282
301
} // namespace clangd
283
302
} // namespace clang
Original file line number Diff line number Diff line change 14
14
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMATTEDSTRING_H
15
15
16
16
#include " llvm/Support/raw_ostream.h"
17
+ #include < cstddef>
17
18
#include < memory>
18
19
#include < string>
19
20
#include < vector>
@@ -86,6 +87,9 @@ class Document {
86
87
// / Adds a block of code. This translates to a ``` block in markdown. In plain
87
88
// / text representation, the code block will be surrounded by newlines.
88
89
void addCodeBlock (std::string Code, std::string Language = " cpp" );
90
+ // / Heading is a special type of paragraph that will be prepended with \p
91
+ // / Level many '#'s in markdown.
92
+ Paragraph &addHeading (size_t Level);
89
93
90
94
BulletList &addBulletList ();
91
95
Original file line number Diff line number Diff line change @@ -469,7 +469,10 @@ markup::Document HoverInfo::present() const {
469
469
// class `X`
470
470
//
471
471
// function `foo` → `int`
472
- markup::Paragraph &Header = Output.addParagraph ();
472
+ // Note that we are making use of a level-3 heading because VSCode renders
473
+ // level 1 and 2 headers in a huge font, see
474
+ // https://github.com/microsoft/vscode/issues/88417 for details.
475
+ markup::Paragraph &Header = Output.addHeading (3 );
473
476
Header.appendText (index ::getSymbolKindString (Kind));
474
477
assert (!Name.empty () && " hover triggered on a nameless symbol" );
475
478
Header.appendCode (Name);
Original file line number Diff line number Diff line change @@ -145,6 +145,15 @@ TEST(Document, Spacer) {
145
145
EXPECT_EQ (D.asPlainText (), " foo\n\n bar" );
146
146
}
147
147
148
+ TEST (Document, Heading) {
149
+ Document D;
150
+ D.addHeading (1 ).appendText (" foo" );
151
+ D.addHeading (2 ).appendText (" bar" );
152
+ D.addParagraph ().appendText (" baz" );
153
+ EXPECT_EQ (D.asMarkdown (), " # foo \n ## bar \n baz" );
154
+ EXPECT_EQ (D.asPlainText (), " foo\n bar\n baz" );
155
+ }
156
+
148
157
TEST (CodeBlock, Render) {
149
158
Document D;
150
159
// Code blocks preserves any extra spaces.
Original file line number Diff line number Diff line change @@ -1631,6 +1631,7 @@ TEST(Hover, DocsFromMostSpecial) {
1631
1631
}
1632
1632
}
1633
1633
}
1634
+
1634
1635
TEST (Hover, Present) {
1635
1636
struct {
1636
1637
const std::function<void (HoverInfo &)> Builder;
@@ -1720,6 +1721,17 @@ def)",
1720
1721
}
1721
1722
}
1722
1723
1724
+ // This is a separate test as headings don't create any differences in plaintext
1725
+ // mode.
1726
+ TEST (Hover, PresentHeadings) {
1727
+ HoverInfo HI;
1728
+ HI.Kind = index ::SymbolKind::Variable;
1729
+ HI.Name = " foo" ;
1730
+ HI.Type = " type" ;
1731
+
1732
+ EXPECT_EQ (HI.present ().asMarkdown (), " ### variable `foo` \\ : `type`" );
1733
+ }
1734
+
1723
1735
} // namespace
1724
1736
} // namespace clangd
1725
1737
} // namespace clang
You can’t perform that action at this time.
0 commit comments