@@ -448,6 +448,11 @@ void DocMarkdownWriter::writeVar(const ASTMarkup::Entry& entry, VarDecl* varDecl
448
448
449
449
out << toSlice (" # " ) << printer.getSlice () << toSlice (" \n\n " );
450
450
451
+ DeclDocumentation declDoc;
452
+ declDoc.parse (entry.m_markup .getUnownedSlice ());
453
+ declDoc.writeDescription (out, this , varDecl);
454
+
455
+ out << toSlice (" ## Signature\n " );
451
456
out << toSlice (" <pre>\n " );
452
457
if (varDecl->hasModifier <HLSLStaticModifier>())
453
458
{
@@ -482,7 +487,9 @@ void DocMarkdownWriter::writeVar(const ASTMarkup::Entry& entry, VarDecl* varDecl
482
487
483
488
out << toSlice (" ;\n </pre>\n\n " );
484
489
485
- writeDescription (entry);
490
+ declDoc.writeSection (out, this , varDecl, DocPageSection::Remarks);
491
+ declDoc.writeSection (out, this , varDecl, DocPageSection::Example);
492
+ declDoc.writeSection (out, this , varDecl, DocPageSection::SeeAlso);
486
493
}
487
494
488
495
void DocMarkdownWriter::writeProperty (const ASTMarkup::Entry& entry, PropertyDecl* propertyDecl)
@@ -494,7 +501,11 @@ void DocMarkdownWriter::writeProperty(const ASTMarkup::Entry& entry, PropertyDec
494
501
printer.addDeclPath (DeclRef<Decl>(propertyDecl));
495
502
out << escapeMarkdownText (printer.getSlice ()) << toSlice (" \n\n " );
496
503
497
- out << toSlice (" ## Definition\n\n " );
504
+ DeclDocumentation declDoc;
505
+ declDoc.parse (entry.m_markup .getUnownedSlice ());
506
+ declDoc.writeDescription (out, this , propertyDecl);
507
+
508
+ out << toSlice (" ## Signature\n\n " );
498
509
499
510
out << toSlice (" <pre>\n <span class='code_keyword'>property</span> " );
500
511
out << translateToHTMLWithLinks (printer.getSlice ());
@@ -520,7 +531,10 @@ void DocMarkdownWriter::writeProperty(const ASTMarkup::Entry& entry, PropertyDec
520
531
}
521
532
out << " }\n </pre>\n\n " ;
522
533
523
- writeDescription (entry);
534
+ declDoc.writeSection (out, this , propertyDecl, DocPageSection::ReturnInfo);
535
+ declDoc.writeSection (out, this , propertyDecl, DocPageSection::Remarks);
536
+ declDoc.writeSection (out, this , propertyDecl, DocPageSection::Example);
537
+ declDoc.writeSection (out, this , propertyDecl, DocPageSection::SeeAlso);
524
538
}
525
539
526
540
void DocMarkdownWriter::writeTypeDef (const ASTMarkup::Entry& entry, TypeDefDecl* typeDefDecl)
@@ -532,7 +546,11 @@ void DocMarkdownWriter::writeTypeDef(const ASTMarkup::Entry& entry, TypeDefDecl*
532
546
_appendAggTypeName (newEntry, typeDefDecl);
533
547
out << toSlice (" \n\n " );
534
548
535
- out << toSlice (" ## Definition\n\n " );
549
+ DeclDocumentation declDoc;
550
+ declDoc.parse (entry.m_markup .getUnownedSlice ());
551
+ declDoc.writeDescription (out, this , typeDefDecl);
552
+
553
+ out << toSlice (" ## Signature\n\n " );
536
554
537
555
out << toSlice (" <pre>\n <span class='code_keyword'>typealias</span> " );
538
556
ASTPrinter printer (m_astBuilder);
@@ -548,7 +566,9 @@ void DocMarkdownWriter::writeTypeDef(const ASTMarkup::Entry& entry, TypeDefDecl*
548
566
out << translateToHTMLWithLinks (typeDefDecl->type ->toString ());
549
567
out << " ;\n </pre>\n\n " ;
550
568
551
- writeDescription (entry);
569
+ declDoc.writeSection (out, this , typeDefDecl, DocPageSection::Remarks);
570
+ declDoc.writeSection (out, this , typeDefDecl, DocPageSection::Example);
571
+ declDoc.writeSection (out, this , typeDefDecl, DocPageSection::SeeAlso);
552
572
}
553
573
554
574
void DocMarkdownWriter::writeExtensionConditions (StringBuilder& out, ExtensionDecl* extensionDecl, const char * prefix, bool isHtml)
@@ -777,7 +797,7 @@ void DocMarkdownWriter::writeSignature(CallableDecl* callableDecl)
777
797
out << " ;\n " ;
778
798
}
779
799
780
- List<DocMarkdownWriter::NameAndText> DocMarkdownWriter::_getUniqueParams (const List<Decl*>& decls, FuncDocumentation * funcDoc)
800
+ List<DocMarkdownWriter::NameAndText> DocMarkdownWriter::_getUniqueParams (const List<Decl*>& decls, DeclDocumentation * funcDoc)
781
801
{
782
802
List<NameAndText> out;
783
803
@@ -1101,7 +1121,7 @@ void ParsedDescription::parse(UnownedStringSlice text)
1101
1121
}
1102
1122
}
1103
1123
1104
- void FuncDocumentation ::parse (const UnownedStringSlice& text)
1124
+ void DeclDocumentation ::parse (const UnownedStringSlice& text)
1105
1125
{
1106
1126
List<UnownedStringSlice> lines;
1107
1127
StringUtil::calcLines (text, lines);
@@ -1176,6 +1196,21 @@ void FuncDocumentation::parse(const UnownedStringSlice& text)
1176
1196
currentSection = DocPageSection::SeeAlso;
1177
1197
line = line.tail (4 ).trim ();
1178
1198
}
1199
+ else if (line.startsWith (" @experimental" ))
1200
+ {
1201
+ currentSection = DocPageSection::ExperimentalCallout;
1202
+ line = line.tail (13 ).trim ();
1203
+ }
1204
+ else if (line.startsWith (" @internal" ))
1205
+ {
1206
+ currentSection = DocPageSection::InternalCallout;
1207
+ line = line.tail (9 ).trim ();
1208
+ }
1209
+ else if (line.startsWith (" @deprecated" ))
1210
+ {
1211
+ currentSection = DocPageSection::InternalCallout;
1212
+ line = line.tail (11 ).trim ();
1213
+ }
1179
1214
sectionBuilders[currentSection] << line << " \n " ;
1180
1215
}
1181
1216
for (auto & kv : sectionBuilders)
@@ -1224,7 +1259,7 @@ void DocMarkdownWriter::writeCallableOverridable(DocumentPage* page, const ASTMa
1224
1259
}
1225
1260
}
1226
1261
1227
- FuncDocumentation funcDoc;
1262
+ DeclDocumentation funcDoc;
1228
1263
funcDoc.parse (descriptionSB.getUnownedSlice ());
1229
1264
funcDoc.parse (additionalDescriptionSB.getUnownedSlice ());
1230
1265
@@ -1402,11 +1437,17 @@ void DocMarkdownWriter::writeEnum(const ASTMarkup::Entry& entry, EnumDecl* enumD
1402
1437
}
1403
1438
out << toSlice (" \n\n " );
1404
1439
1440
+ DeclDocumentation declDoc;
1441
+ declDoc.parse (entry.m_markup .getUnownedSlice ());
1442
+ declDoc.writeDescription (out, this , enumDecl);
1443
+
1405
1444
out << toSlice (" ## Values \n\n " );
1406
1445
1407
1446
_appendAsBullets (_getAsNameAndTextList (enumDecl->getMembersOfType <EnumCaseDecl>()), false , ' _' );
1408
1447
1409
- writeDescription (entry);
1448
+ declDoc.writeSection (out, this , enumDecl, DocPageSection::Remarks);
1449
+ declDoc.writeSection (out, this , enumDecl, DocPageSection::Example);
1450
+ declDoc.writeSection (out, this , enumDecl, DocPageSection::SeeAlso);
1410
1451
}
1411
1452
1412
1453
void DocMarkdownWriter::_appendEscaped (const UnownedStringSlice& text)
@@ -1589,7 +1630,10 @@ void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry&
1589
1630
}
1590
1631
}
1591
1632
1592
- writeDescription (primaryEntry);
1633
+ DeclDocumentation declDoc;
1634
+ declDoc.parse (primaryEntry.m_markup .getUnownedSlice ());
1635
+ declDoc.writeDescription (out, this , aggTypeDecl);
1636
+
1593
1637
if (GenericDecl* genericDecl = as<GenericDecl>(aggTypeDecl->parentDecl ))
1594
1638
{
1595
1639
// The parameters, in order
@@ -1754,6 +1798,9 @@ void DocMarkdownWriter::writeAggType(DocumentPage* page, const ASTMarkup::Entry&
1754
1798
}
1755
1799
}
1756
1800
}
1801
+ declDoc.writeSection (out, this , aggTypeDecl, DocPageSection::Remarks);
1802
+ declDoc.writeSection (out, this , aggTypeDecl, DocPageSection::Example);
1803
+ declDoc.writeSection (out, this , aggTypeDecl, DocPageSection::SeeAlso);
1757
1804
}
1758
1805
1759
1806
String DocMarkdownWriter::escapeMarkdownText (String text)
@@ -1981,26 +2028,61 @@ void DocMarkdownWriter::writePreamble()
1981
2028
}
1982
2029
}
1983
2030
1984
- bool DocMarkdownWriter::writeDescription ( const ASTMarkup::Entry& entry )
2031
+ const char * getSectionTitle (DocPageSection section )
1985
2032
{
1986
- auto & out = *m_builder;
1987
-
1988
- if (entry.m_markup .trim ().getLength () > 0 )
2033
+ switch (section)
1989
2034
{
1990
- out << toSlice (" ## Description\n\n " );
2035
+ case DocPageSection::Description: return " Description" ;
2036
+ case DocPageSection::Parameter: return " Parameters" ;
2037
+ case DocPageSection::ReturnInfo: return " Return value" ;
2038
+ case DocPageSection::Remarks: return " Remarks" ;
2039
+ case DocPageSection::Example: return " Example" ;
2040
+ case DocPageSection::SeeAlso: return " See also" ;
2041
+ default : return " " ;
2042
+ }
2043
+ }
1991
2044
1992
- out << entry.m_markup .getUnownedSlice ();
1993
- #if 0
1994
- UnownedStringSlice text(entry.m_markup.getUnownedSlice()), line;
1995
- while (StringUtil::extractLine(text, line))
1996
- {
1997
- out << line << toSlice("\n");
1998
- }
1999
- #endif
2000
- out << toSlice (" \n " );
2001
- return true ;
2045
+ void DeclDocumentation::writeDescription (StringBuilder& out, DocMarkdownWriter* writer, Decl* decl)
2046
+ {
2047
+ // Write all callout sections first.
2048
+ writeSection (out, writer, decl, DocPageSection::DeprecatedCallout);
2049
+ writeSection (out, writer, decl, DocPageSection::ExperimentalCallout);
2050
+ writeSection (out, writer, decl, DocPageSection::InternalCallout);
2051
+
2052
+ // Write description section.
2053
+ writeSection (out, writer, decl, DocPageSection::Description);
2054
+ }
2055
+
2056
+ void DeclDocumentation::writeSection (StringBuilder& out, DocMarkdownWriter* writer, Decl* decl, DocPageSection section)
2057
+ {
2058
+ SLANG_UNUSED (decl);
2059
+ ParsedDescription* sectionDoc = sections.tryGetValue (section);
2060
+ if (!sectionDoc)
2061
+ return ;
2062
+
2063
+ switch (section)
2064
+ {
2065
+ case DocPageSection::DeprecatedCallout:
2066
+ out << " > #### Deprecated Feature\n " ;
2067
+ out << " > The feature described in this page is marked as deprecated, and may be removed in a future release.\n " ;
2068
+ out << " > Users are advised to avoid using this feature, and to migrate to a newer alternative.\n " ;
2069
+ return ;
2070
+ case DocPageSection::ExperimentalCallout:
2071
+ out << " > #### Experimental Feature\n " ;
2072
+ out << " > The feature described in this page is marked as experimental, and may be subject to change in future releases.\n " ;
2073
+ out << " > Users are advised that any code that depend on this feature may not be compilable by future versions of the compiler.\n " ;
2074
+ return ;
2075
+ case DocPageSection::InternalCallout:
2076
+ out << " > #### Internal Feature\n " ;
2077
+ out << " > The feature described in this page is marked as an internal implementation detail, and is not intended for use by end-users.\n " ;
2078
+ out << " > Users are advised to avoid using this declaration directly, as it may be removed or changed in future releases.\n " ;
2079
+ return ;
2080
+ }
2081
+ if (sectionDoc && sectionDoc->ownedText .getLength () > 0 )
2082
+ {
2083
+ out << " ## \" " << getSectionTitle (section) << " \n\n " ;
2084
+ sectionDoc->write (writer, out);
2002
2085
}
2003
- return false ;
2004
2086
}
2005
2087
2006
2088
void DocMarkdownWriter::createPage (DocMarkdownWriter::WriteDeclMode mode, ASTMarkup::Entry& entry, Decl* decl)
0 commit comments