Skip to content

Commit 8a505a1

Browse files
authored
[clangd] Doxygen Parsing: Add proper handling of \note, \warning and \retval command + change render kind of command arguments + add preprocessing for markdown code blocks/spans (#156365)
Fixes some followup issues from clangd/clangd#529. `\note` and `\warning`: In the hover card, they are now displayed with heading and enclosing rulers. `\retval` commands: Each `\retval` command is now a bullet point under the return section of the hover card. Added a Markdown preprocessing step before parsing the documentation with the doxygen parser. This mainly replaces markdown code blocks with `@code...@endcode` commands.
1 parent 22a02b6 commit 8a505a1

File tree

6 files changed

+927
-157
lines changed

6 files changed

+927
-157
lines changed

clang-tools-extra/clangd/Hover.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,12 @@ markup::Document HoverInfo::presentDoxygen() const {
15371537
SymbolDocCommentVisitor SymbolDoc(Documentation, CommentOpts);
15381538

15391539
if (SymbolDoc.hasBriefCommand()) {
1540+
if (Kind != index::SymbolKind::Parameter &&
1541+
Kind != index::SymbolKind::TemplateTypeParm)
1542+
// Only add a "Brief" heading if we are not documenting a parameter.
1543+
// Parameters only have a brief section and adding the brief header would
1544+
// be redundant.
1545+
Output.addHeading(3).appendText("Brief");
15401546
SymbolDoc.briefToMarkup(Output.addParagraph());
15411547
Output.addRuler();
15421548
}
@@ -1550,7 +1556,7 @@ markup::Document HoverInfo::presentDoxygen() const {
15501556
// Returns
15511557
// `type` - description
15521558
if (TemplateParameters && !TemplateParameters->empty()) {
1553-
Output.addParagraph().appendBoldText("Template Parameters:");
1559+
Output.addHeading(3).appendText("Template Parameters");
15541560
markup::BulletList &L = Output.addBulletList();
15551561
for (const auto &Param : *TemplateParameters) {
15561562
markup::Paragraph &P = L.addItem().addParagraph();
@@ -1564,7 +1570,7 @@ markup::Document HoverInfo::presentDoxygen() const {
15641570
}
15651571

15661572
if (Parameters && !Parameters->empty()) {
1567-
Output.addParagraph().appendBoldText("Parameters:");
1573+
Output.addHeading(3).appendText("Parameters");
15681574
markup::BulletList &L = Output.addBulletList();
15691575
for (const auto &Param : *Parameters) {
15701576
markup::Paragraph &P = L.addItem().addParagraph();
@@ -1583,23 +1589,23 @@ markup::Document HoverInfo::presentDoxygen() const {
15831589
if (ReturnType &&
15841590
((ReturnType->Type != "void" && !ReturnType->AKA.has_value()) ||
15851591
(ReturnType->AKA.has_value() && ReturnType->AKA != "void"))) {
1586-
Output.addParagraph().appendBoldText("Returns:");
1592+
Output.addHeading(3).appendText("Returns");
15871593
markup::Paragraph &P = Output.addParagraph();
15881594
P.appendCode(llvm::to_string(*ReturnType));
15891595

15901596
if (SymbolDoc.hasReturnCommand()) {
15911597
P.appendText(" - ");
15921598
SymbolDoc.returnToMarkup(P);
15931599
}
1600+
1601+
SymbolDoc.retvalsToMarkup(Output);
15941602
Output.addRuler();
15951603
}
15961604

1597-
// add specially handled doxygen commands.
1598-
SymbolDoc.warningsToMarkup(Output);
1599-
SymbolDoc.notesToMarkup(Output);
1600-
1601-
// add any other documentation.
1602-
SymbolDoc.docToMarkup(Output);
1605+
if (SymbolDoc.hasDetailedDoc()) {
1606+
Output.addHeading(3).appendText("Details");
1607+
SymbolDoc.detailedDocToMarkup(Output);
1608+
}
16031609

16041610
Output.addRuler();
16051611

0 commit comments

Comments
 (0)