diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 75302b0dc3264..92a4117c4e534 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -97,6 +97,12 @@ static void insertComment(Object &Description, json::Value &Comment, } } +static json::Value extractTextComments(Object *ParagraphComment) { + if (!ParagraphComment) + return json::Object(); + return *ParagraphComment->get("Children"); +} + static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -117,14 +123,9 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { } case CommentKind::CK_BlockCommandComment: { - Child.insert({"Command", I.Name}); - // TODO: The "Children" level of nesting isn't needed for comments that - // don't hold additional information at the top level. BriefComments can - // just be an array of ParagraphComments. - Child.insert({"Children", ChildArr}); - Obj.insert({commentKindToString(I.Kind), ChildVal}); + auto TextCommentsArray = extractTextComments(CARef.front().getAsObject()); if (I.Name == "brief") - insertComment(Description, ChildVal, "BriefComments"); + insertComment(Description, TextCommentsArray, "BriefComments"); return Obj; } @@ -201,8 +202,8 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { case CommentKind::CK_FullComment: case CommentKind::CK_ParagraphComment: { Child.insert({"Children", ChildArr}); - Obj.insert({commentKindToString(I.Kind), ChildVal}); - return Obj; + Child["ParagraphComment"] = true; + return Child; } case CommentKind::CK_Unknown: { @@ -239,9 +240,11 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, json::Value Comment = serializeComment(*CommentInfo, Description); // if a ParagraphComment is returned, then it is a top-level comment that // needs to be inserted manually. - if (auto *ParagraphComment = - Comment.getAsObject()->get("ParagraphComment")) - insertComment(Description, *ParagraphComment, "ParagraphComments"); + if (auto *ParagraphComment = Comment.getAsObject(); + ParagraphComment->get("ParagraphComment")) { + auto TextCommentsArray = extractTextComments(ParagraphComment); + insertComment(Description, TextCommentsArray, "ParagraphComments"); + } } Obj["Description"] = std::move(Description); } diff --git a/clang-tools-extra/clang-doc/assets/comment-template.mustache b/clang-tools-extra/clang-doc/assets/comment-template.mustache index b793bad55cf6c..f2edb1b2eb9ac 100644 --- a/clang-tools-extra/clang-doc/assets/comment-template.mustache +++ b/clang-tools-extra/clang-doc/assets/comment-template.mustache @@ -6,14 +6,18 @@ This file defines templates for generating comments }} {{#BriefComments}} - {{#Children}} - {{>Comments}} - {{/Children}} +
{{TextComment}}
+ {{/.}} +{{TextComment}}
+ {{/.}} +