@@ -83,7 +83,27 @@ serializeLocation(const Location &Loc,
83
83
return LocationObj;
84
84
}
85
85
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) {
87
107
// taken from PR #142273
88
108
Object Obj = Object ();
89
109
@@ -94,7 +114,7 @@ static json::Value serializeComment(const CommentInfo &I) {
94
114
auto &CARef = *ChildArr.getAsArray ();
95
115
CARef.reserve (I.Children .size ());
96
116
for (const auto &C : I.Children )
97
- CARef.emplace_back (serializeComment (*C));
117
+ CARef.emplace_back (serializeComment (*C, Description ));
98
118
99
119
switch (I.Kind ) {
100
120
case CommentKind::CK_TextComment: {
@@ -103,9 +123,9 @@ static json::Value serializeComment(const CommentInfo &I) {
103
123
}
104
124
105
125
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 " );
109
129
return Obj;
110
130
}
111
131
@@ -137,7 +157,10 @@ static json::Value serializeComment(const CommentInfo &I) {
137
157
if (!I.CloseName .empty ())
138
158
Child.insert ({" CloseName" , I.CloseName });
139
159
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" );
141
164
return Obj;
142
165
}
143
166
@@ -179,8 +202,8 @@ static json::Value serializeComment(const CommentInfo &I) {
179
202
case CommentKind::CK_FullComment:
180
203
case CommentKind::CK_ParagraphComment: {
181
204
Child.insert ({" Children" , ChildArr});
182
- Obj. insert ({ commentKindToString (I. Kind ), ChildVal}) ;
183
- return Obj ;
205
+ Child[ " ParagraphComment " ] = true ;
206
+ return Child ;
184
207
}
185
208
186
209
case CommentKind::CK_Unknown: {
@@ -210,12 +233,20 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210
233
}
211
234
212
235
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);
219
250
}
220
251
221
252
// Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments