@@ -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+ 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 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: {
@@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) {
104118
105119 case CommentKind::CK_BlockCommandComment: {
106120 Child.insert ({" Command" , I.Name });
121+ // TODO: The "Children" level of nesting isn't needed for comments that
122+ // don't hold additional information at the top level. BriefComments can
123+ // just be an array of ParagraphComments.
107124 Child.insert ({" Children" , ChildArr});
108125 Obj.insert ({commentKindToString (I.Kind ), ChildVal});
126+ if (I.Name == " brief" )
127+ insertComment (Description, ChildVal, " BriefComments" );
109128 return Obj;
110129 }
111130
@@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) {
137156 if (!I.CloseName .empty ())
138157 Child.insert ({" CloseName" , I.CloseName });
139158 Child.insert ({" Children" , ChildArr});
140- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
159+ if (I.CloseName == " endcode" )
160+ insertComment (Description, ChildVal, " CodeComments" );
161+ else if (I.CloseName == " endverbatim" )
162+ insertComment (Description, ChildVal, " VerbatimComments" );
141163 return Obj;
142164 }
143165
@@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210232 }
211233
212234 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;
235+ Object Description = Object ();
236+ // Skip straight to the FullComment's children
237+ auto &Comments = I.Description .at (0 ).Children ;
238+ for (const auto &CommentInfo : Comments) {
239+ json::Value Comment = serializeComment (*CommentInfo, Description);
240+ // if a ParagraphComment is returned, then it is a top-level comment that
241+ // needs to be inserted manually.
242+ if (auto *ParagraphComment =
243+ Comment.getAsObject ()->get (" ParagraphComment" ))
244+ insertComment (Description, *ParagraphComment, " ParagraphComments" );
245+ }
246+ Obj[" Description" ] = std::move (Description);
219247 }
220248
221249 // Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments