@@ -83,7 +83,39 @@ 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 json::Value extractVerbatimComments (json::Array VerbatimLines) {
107+ json::Value TextArray = json::Array ();
108+ auto &TextArrayRef = *TextArray.getAsArray ();
109+ for (auto &Line : VerbatimLines)
110+ TextArrayRef.push_back (*Line.getAsObject ()
111+ ->get (" VerbatimBlockLineComment" )
112+ ->getAsObject ()
113+ ->get (" Text" ));
114+
115+ return TextArray;
116+ }
117+
118+ static Object serializeComment (const CommentInfo &I, Object &Description) {
87119 // taken from PR #142273
88120 Object Obj = Object ();
89121
@@ -94,7 +126,7 @@ static json::Value serializeComment(const CommentInfo &I) {
94126 auto &CARef = *ChildArr.getAsArray ();
95127 CARef.reserve (I.Children .size ());
96128 for (const auto &C : I.Children )
97- CARef.emplace_back (serializeComment (*C));
129+ CARef.emplace_back (serializeComment (*C, Description ));
98130
99131 switch (I.Kind ) {
100132 case CommentKind::CK_TextComment: {
@@ -103,9 +135,11 @@ static json::Value serializeComment(const CommentInfo &I) {
103135 }
104136
105137 case CommentKind::CK_BlockCommandComment: {
106- Child.insert ({" Command" , I.Name });
107- Child.insert ({" Children" , ChildArr});
108- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
138+ auto TextCommentsArray = extractTextComments (CARef.front ().getAsObject ());
139+ if (I.Name == " brief" )
140+ insertComment (Description, TextCommentsArray, " BriefComments" );
141+ else if (I.Name == " return" )
142+ insertComment (Description, TextCommentsArray, " ReturnComments" );
109143 return Obj;
110144 }
111145
@@ -127,17 +161,20 @@ static json::Value serializeComment(const CommentInfo &I) {
127161 Child.insert ({" ParamName" , I.ParamName });
128162 Child.insert ({" Direction" , I.Direction });
129163 Child.insert ({" Explicit" , I.Explicit });
130- Child.insert ({" Children" , ChildArr});
131- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
164+ auto TextCommentsArray = extractTextComments (CARef.front ().getAsObject ());
165+ Child.insert ({" Children" , TextCommentsArray});
166+ if (I.Kind == CommentKind::CK_ParamCommandComment)
167+ insertComment (Description, ChildVal, " ParamComments" );
132168 return Obj;
133169 }
134170
135171 case CommentKind::CK_VerbatimBlockComment: {
136- Child.insert ({" Text" , I.Text });
137- if (!I.CloseName .empty ())
138- Child.insert ({" CloseName" , I.CloseName });
139- Child.insert ({" Children" , ChildArr});
140- Obj.insert ({commentKindToString (I.Kind ), ChildVal});
172+ if (I.CloseName == " endcode" ) {
173+ // We don't support \code language specification
174+ auto TextCommentsArray = extractVerbatimComments (CARef);
175+ insertComment (Description, TextCommentsArray, " CodeComments" );
176+ } else if (I.CloseName == " endverbatim" )
177+ insertComment (Description, ChildVal, " VerbatimComments" );
141178 return Obj;
142179 }
143180
@@ -179,8 +216,8 @@ static json::Value serializeComment(const CommentInfo &I) {
179216 case CommentKind::CK_FullComment:
180217 case CommentKind::CK_ParagraphComment: {
181218 Child.insert ({" Children" , ChildArr});
182- Obj. insert ({ commentKindToString (I. Kind ), ChildVal}) ;
183- return Obj ;
219+ Child[ " ParagraphComment " ] = true ;
220+ return Child ;
184221 }
185222
186223 case CommentKind::CK_Unknown: {
@@ -210,12 +247,20 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210247 }
211248
212249 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;
250+ Object Description = Object ();
251+ // Skip straight to the FullComment's children
252+ auto &Comments = I.Description .at (0 ).Children ;
253+ for (const auto &CommentInfo : Comments) {
254+ json::Value Comment = serializeComment (*CommentInfo, Description);
255+ // if a ParagraphComment is returned, then it is a top-level comment that
256+ // needs to be inserted manually.
257+ if (auto *ParagraphComment = Comment.getAsObject ();
258+ ParagraphComment->get (" ParagraphComment" )) {
259+ auto TextCommentsArray = extractTextComments (ParagraphComment);
260+ insertComment (Description, TextCommentsArray, " ParagraphComments" );
261+ }
262+ }
263+ Obj[" Description" ] = std::move (Description);
219264 }
220265
221266 // Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments