@@ -83,7 +83,21 @@ serializeLocation(const Location &Loc,
8383 return LocationObj;
8484}
8585
86- static json::Value serializeComment (const CommentInfo &I) {
86+ static void insertComment (Object &Description, json::Value &Comment,
87+ std::string Key) {
88+ auto *CommentArray = Description.getArray (Key);
89+ if (!CommentArray) {
90+ auto CommentsArray = json::Array ();
91+ CommentsArray.push_back (Comment);
92+ Description[Key] = std::move (CommentsArray);
93+ Description[" Has" + Key] = true ;
94+ } else {
95+ CommentArray->push_back (Comment);
96+ Description[Key] = std::move (*CommentArray);
97+ }
98+ }
99+
100+ static Object serializeComment (const CommentInfo &I, Object &Description) {
87101 // taken from PR #142273
88102 Object Obj = Object ();
89103
@@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) {
94108 auto &CARef = *ChildArr.getAsArray ();
95109 CARef.reserve (I.Children .size ());
96110 for (const auto &C : I.Children )
97- CARef.emplace_back (serializeComment (*C));
111+ CARef.emplace_back (serializeComment (*C, Description ));
98112
99113 switch (I.Kind ) {
100114 case CommentKind::CK_TextComment: {
@@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) {
106120 Child.insert ({" Command" , I.Name });
107121 Child.insert ({" Children" , ChildArr});
108122 Obj.insert ({commentKindToString (I.Kind ), ChildVal});
123+ if (I.Name == " brief" )
124+ insertComment (Description, ChildVal, " BriefComments" );
109125 return Obj;
110126 }
111127
@@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) {
137153 if (!I.CloseName .empty ())
138154 Child.insert ({" CloseName" , I.CloseName });
139155 Child.insert ({" Children" , ChildArr});
140- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
156+ if (I.CloseName == " endcode" )
157+ insertComment (Description, ChildVal, " CodeComments" );
158+ else if (I.CloseName == " endverbatim" )
159+ insertComment (Description, ChildVal, " VerbatimComments" );
141160 return Obj;
142161 }
143162
@@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210229 }
211230
212231 if (!I.Description .empty ()) {
213- json::Value DescArray = json::Array ();
214- auto &DescArrayRef = *DescArray.getAsArray ();
215- DescArrayRef.reserve (I.Description .size ());
216- for (const auto &Comment : I.Description )
217- DescArrayRef.push_back (serializeComment (Comment));
218- Obj[" Description" ] = DescArray;
232+ Object Description = Object ();
233+ // Skip straight to the FullComment's children
234+ auto &Comments = I.Description .at (0 ).Children ;
235+ for (const auto &CommentInfo : Comments) {
236+ json::Value Comment = serializeComment (*CommentInfo, Description);
237+ // Paragraph comments might not be children
238+ if (auto *ParagraphComment =
239+ Comment.getAsObject ()->get (" ParagraphComment" ))
240+ insertComment (Description, *ParagraphComment, " ParagraphComments" );
241+ }
242+ Obj[" Description" ] = std::move (Description);
219243 }
220244
221245 // Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments