@@ -347,7 +347,7 @@ void enhanceFromIndex(HoverInfo &Hover, const NamedDecl &ND,
347347 LookupRequest Req;
348348 Req.IDs .insert (ID);
349349 Index->lookup (Req, [&](const Symbol &S) {
350- Hover.Documentation = std::string ( S.Documentation );
350+ Hover.Documentation = S.Documentation . toOwned ( );
351351 });
352352}
353353
@@ -625,10 +625,11 @@ HoverInfo getHoverContents(const NamedDecl *D, const PrintingPolicy &PP,
625625
626626 HI.Name = printName (Ctx, *D);
627627 const auto *CommentD = getDeclForComment (D);
628- HI.Documentation = getDeclComment (Ctx, *CommentD);
628+ HI.Documentation = getDeclDocumentation (Ctx, *CommentD);
629629 enhanceFromIndex (HI, *CommentD, Index);
630630 if (HI.Documentation .empty ())
631- HI.Documentation = synthesizeDocumentation (D);
631+ HI.Documentation =
632+ SymbolDocumentationOwned::descriptionOnly (synthesizeDocumentation (D));
632633
633634 HI.Kind = index::getSymbolInfo (D).Kind ;
634635
@@ -682,7 +683,8 @@ getPredefinedExprHoverContents(const PredefinedExpr &PE, ASTContext &Ctx,
682683 HoverInfo HI;
683684 HI.Name = PE.getIdentKindName ();
684685 HI.Kind = index::SymbolKind::Variable;
685- HI.Documentation = " Name of the current function (predefined variable)" ;
686+ HI.Documentation = SymbolDocumentationOwned::descriptionOnly (
687+ " Name of the current function (predefined variable)" );
686688 if (const StringLiteral *Name = PE.getFunctionName ()) {
687689 HI.Value .emplace ();
688690 llvm::raw_string_ostream OS (*HI.Value );
@@ -856,7 +858,7 @@ HoverInfo getDeducedTypeHoverContents(QualType QT, const syntax::Token &Tok,
856858
857859 if (const auto *D = QT->getAsTagDecl ()) {
858860 const auto *CommentD = getDeclForComment (D);
859- HI.Documentation = getDeclComment (ASTCtx, *CommentD);
861+ HI.Documentation = getDeclDocumentation (ASTCtx, *CommentD);
860862 enhanceFromIndex (HI, *CommentD, Index);
861863 }
862864 }
@@ -956,7 +958,8 @@ std::optional<HoverInfo> getHoverContents(const Attr *A, ParsedAST &AST) {
956958 llvm::raw_string_ostream OS (HI.Definition );
957959 A->printPretty (OS, AST.getASTContext ().getPrintingPolicy ());
958960 }
959- HI.Documentation = Attr::getDocumentation (A->getKind ()).str ();
961+ HI.Documentation = SymbolDocumentationOwned::descriptionOnly (
962+ Attr::getDocumentation (A->getKind ()).str ());
960963 return HI;
961964}
962965
@@ -1455,6 +1458,10 @@ markup::Document HoverInfo::present() const {
14551458
14561459 // Put a linebreak after header to increase readability.
14571460 Output.addRuler ();
1461+
1462+ if (!Documentation.Brief .empty ())
1463+ parseDocumentation (Documentation.Brief , Output);
1464+
14581465 // Print Types on their own lines to reduce chances of getting line-wrapped by
14591466 // editor, as they might be long.
14601467 if (ReturnType) {
@@ -1463,15 +1470,44 @@ markup::Document HoverInfo::present() const {
14631470 // Parameters:
14641471 // - `bool param1`
14651472 // - `int param2 = 5`
1466- Output.addParagraph ().appendText (" → " ).appendCode (
1473+ auto &P = Output.addParagraph ().appendText (" → " ).appendCode (
14671474 llvm::to_string (*ReturnType));
1468- }
14691475
1476+ if (!Documentation.Returns .empty ())
1477+ P.appendText (" : " ).appendText (Documentation.Returns );
1478+ }
14701479 if (Parameters && !Parameters->empty ()) {
14711480 Output.addParagraph ().appendText (" Parameters: " );
14721481 markup::BulletList &L = Output.addBulletList ();
1473- for (const auto &Param : *Parameters)
1474- L.addItem ().addParagraph ().appendCode (llvm::to_string (Param));
1482+
1483+ llvm::SmallVector<ParameterDocumentationOwned> ParamDocs =
1484+ Documentation.Parameters ;
1485+
1486+ for (const auto &Param : *Parameters) {
1487+ auto &Paragraph = L.addItem ().addParagraph ();
1488+ Paragraph.appendCode (llvm::to_string (Param));
1489+
1490+ if (Param.Name .has_value ()) {
1491+ auto ParamDoc = std::find_if (ParamDocs.begin (), ParamDocs.end (),
1492+ [Param](const auto &ParamDoc) {
1493+ return Param.Name == ParamDoc.Name ;
1494+ });
1495+ if (ParamDoc != ParamDocs.end ()) {
1496+ Paragraph.appendText (" : " ).appendText (ParamDoc->Description );
1497+ ParamDocs.erase (ParamDoc);
1498+ }
1499+ }
1500+ }
1501+
1502+ // We erased all parameters that matched, but some may still be left,
1503+ // usually typos. Let's also print them here.
1504+ for (const auto &ParamDoc : ParamDocs) {
1505+ L.addItem ()
1506+ .addParagraph ()
1507+ .appendCode (ParamDoc.Name )
1508+ .appendText (" : " )
1509+ .appendText (ParamDoc.Description );
1510+ }
14751511 }
14761512
14771513 // Don't print Type after Parameters or ReturnType as this will just duplicate
@@ -1518,8 +1554,30 @@ markup::Document HoverInfo::present() const {
15181554 Output.addParagraph ().appendText (OS.str ());
15191555 }
15201556
1521- if (!Documentation.empty ())
1522- parseDocumentation (Documentation, Output);
1557+ if (!Documentation.Description .empty ())
1558+ parseDocumentation (Documentation.Description , Output);
1559+
1560+ if (!Documentation.Warnings .empty ()) {
1561+ Output.addRuler ();
1562+ Output.addParagraph ()
1563+ .appendText (" Warning" )
1564+ .appendText (Documentation.Warnings .size () > 1 ? " s" : " " )
1565+ .appendText (" : " );
1566+ markup::BulletList &L = Output.addBulletList ();
1567+ for (const auto &Warning : Documentation.Warnings )
1568+ parseDocumentation (Warning, L.addItem ());
1569+ }
1570+
1571+ if (!Documentation.Notes .empty ()) {
1572+ Output.addRuler ();
1573+ Output.addParagraph ()
1574+ .appendText (" Note" )
1575+ .appendText (Documentation.Notes .size () > 1 ? " s" : " " )
1576+ .appendText (" : " );
1577+ markup::BulletList &L = Output.addBulletList ();
1578+ for (const auto &Note : Documentation.Notes )
1579+ parseDocumentation (Note, L.addItem ());
1580+ }
15231581
15241582 if (!Definition.empty ()) {
15251583 Output.addRuler ();
0 commit comments