@@ -83,7 +83,27 @@ 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+ StringRef Key) {
88+ auto DescriptionIt = Description.find (Key);
89+
90+ if (DescriptionIt == Description.end ()) {
91+ auto CommentsArray = json::Array ();
92+ CommentsArray.push_back (Comment);
93+ Description[Key] = std::move (CommentsArray);
94+ Description[" Has" + Key.str ()] = true ;
95+ } else {
96+ DescriptionIt->getSecond ().getAsArray ()->push_back (Comment);
97+ }
98+ }
99+
100+ static json::Value extractTextComments (Object *ParagraphComment) {
101+ if (!ParagraphComment)
102+ return json::Object ();
103+ return *ParagraphComment->get (" Children" );
104+ }
105+
106+ static Object serializeComment (const CommentInfo &I, Object &Description) {
87107 // taken from PR #142273
88108 Object Obj = Object ();
89109
@@ -94,7 +114,7 @@ static json::Value serializeComment(const CommentInfo &I) {
94114 auto &CARef = *ChildArr.getAsArray ();
95115 CARef.reserve (I.Children .size ());
96116 for (const auto &C : I.Children )
97- CARef.emplace_back (serializeComment (*C));
117+ CARef.emplace_back (serializeComment (*C, Description ));
98118
99119 switch (I.Kind ) {
100120 case CommentKind::CK_TextComment: {
@@ -103,9 +123,9 @@ static json::Value serializeComment(const CommentInfo &I) {
103123 }
104124
105125 case CommentKind::CK_BlockCommandComment: {
106- Child. insert ({ " Command " , I. Name } );
107- Child. insert ({ " Children " , ChildArr});
108- Obj. insert ({ commentKindToString (I. Kind ), ChildVal} );
126+ auto TextCommentsArray = extractTextComments (CARef. front (). getAsObject () );
127+ if (I. Name == " brief " )
128+ insertComment (Description, TextCommentsArray, " BriefComments " );
109129 return Obj;
110130 }
111131
@@ -137,7 +157,10 @@ static json::Value serializeComment(const CommentInfo &I) {
137157 if (!I.CloseName .empty ())
138158 Child.insert ({" CloseName" , I.CloseName });
139159 Child.insert ({" Children" , ChildArr});
140- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
160+ if (I.CloseName == " endcode" )
161+ insertComment (Description, ChildVal, " CodeComments" );
162+ else if (I.CloseName == " endverbatim" )
163+ insertComment (Description, ChildVal, " VerbatimComments" );
141164 return Obj;
142165 }
143166
@@ -179,8 +202,8 @@ static json::Value serializeComment(const CommentInfo &I) {
179202 case CommentKind::CK_FullComment:
180203 case CommentKind::CK_ParagraphComment: {
181204 Child.insert ({" Children" , ChildArr});
182- Obj. insert ({ commentKindToString (I. Kind ), ChildVal}) ;
183- return Obj ;
205+ Child[ " ParagraphComment " ] = true ;
206+ return Child ;
184207 }
185208
186209 case CommentKind::CK_Unknown: {
@@ -210,12 +233,20 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210233 }
211234
212235 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;
236+ Object Description = Object ();
237+ // Skip straight to the FullComment's children
238+ auto &Comments = I.Description .at (0 ).Children ;
239+ for (const auto &CommentInfo : Comments) {
240+ json::Value Comment = serializeComment (*CommentInfo, Description);
241+ // if a ParagraphComment is returned, then it is a top-level comment that
242+ // needs to be inserted manually.
243+ if (auto *ParagraphComment = Comment.getAsObject ();
244+ ParagraphComment->get (" ParagraphComment" )) {
245+ auto TextCommentsArray = extractTextComments (ParagraphComment);
246+ insertComment (Description, TextCommentsArray, " ParagraphComments" );
247+ }
248+ }
249+ Obj[" Description" ] = std::move (Description);
219250 }
220251
221252 // Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments