@@ -83,7 +83,21 @@ 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 Object serializeComment (const CommentInfo &I, Object &Description) {
87
101
// taken from PR #142273
88
102
Object Obj = Object ();
89
103
@@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) {
94
108
auto &CARef = *ChildArr.getAsArray ();
95
109
CARef.reserve (I.Children .size ());
96
110
for (const auto &C : I.Children )
97
- CARef.emplace_back (serializeComment (*C));
111
+ CARef.emplace_back (serializeComment (*C, Description ));
98
112
99
113
switch (I.Kind ) {
100
114
case CommentKind::CK_TextComment: {
@@ -104,8 +118,13 @@ static json::Value serializeComment(const CommentInfo &I) {
104
118
105
119
case CommentKind::CK_BlockCommandComment: {
106
120
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.
107
124
Child.insert ({" Children" , ChildArr});
108
125
Obj.insert ({commentKindToString (I.Kind ), ChildVal});
126
+ if (I.Name == " brief" )
127
+ insertComment (Description, ChildVal, " BriefComments" );
109
128
return Obj;
110
129
}
111
130
@@ -137,7 +156,10 @@ static json::Value serializeComment(const CommentInfo &I) {
137
156
if (!I.CloseName .empty ())
138
157
Child.insert ({" CloseName" , I.CloseName });
139
158
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" );
141
163
return Obj;
142
164
}
143
165
@@ -210,12 +232,18 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
210
232
}
211
233
212
234
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);
219
247
}
220
248
221
249
// Namespaces aren't SymbolInfos, so they dont have a DefLoc
0 commit comments