-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-doc] Do not serialize empty text comments #169087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evelez7
wants to merge
1
commit into
main
Choose a base branch
from
users/evelez7/clang-doc-empty-text-comments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−103
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,8 +84,24 @@ serializeLocation(const Location &Loc, | |
| return LocationObj; | ||
| } | ||
|
|
||
| /// Insert comments into a key in the Description object. | ||
| /// | ||
| /// \param Comment Either an Object or Array, depending on the comment type | ||
| /// \param Key The type (Brief, Code, etc.) of comment to be inserted | ||
| static void insertComment(Object &Description, json::Value &Comment, | ||
| StringRef Key) { | ||
| // The comment has a Children array for the actual text, with meta attributes | ||
| // alongside it in the Object. | ||
| if (auto *Obj = Comment.getAsObject(); Obj) { | ||
| if (auto *Children = Obj->getArray("Children"); | ||
| !Children || Children->empty()) | ||
| return; | ||
| } | ||
| // The comment is just an array of text comments. | ||
| else if (auto *Array = Comment.getAsArray(); !Array) { | ||
| return; | ||
| } | ||
|
|
||
| auto DescriptionIt = Description.find(Key); | ||
|
|
||
| if (DescriptionIt == Description.end()) { | ||
|
|
@@ -98,10 +114,29 @@ static void insertComment(Object &Description, json::Value &Comment, | |
| } | ||
| } | ||
|
|
||
| /// Takes the nested "Children" array from a comment Object. | ||
| /// | ||
| /// \return a json::Array of comments, possible json::Value::Kind::Null | ||
| static json::Value extractTextComments(Object *ParagraphComment) { | ||
| if (!ParagraphComment) | ||
| return json::Object(); | ||
| return *ParagraphComment->get("Children"); | ||
| return json::Value(nullptr); | ||
| json::Value *Children = ParagraphComment->get("Children"); | ||
| if (!Children) | ||
| return json::Value(nullptr); | ||
| auto ChildrenArray = *Children->getAsArray(); | ||
| auto ChildrenIt = ChildrenArray.begin(); | ||
| while (ChildrenIt != ChildrenArray.end()) { | ||
| auto *ChildObj = ChildrenIt->getAsObject(); | ||
| if (!ChildObj) | ||
| break; | ||
|
Comment on lines
+130
to
+131
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you just return on the first one that isn't an object? |
||
| auto TextComment = ChildObj->getString("TextComment"); | ||
| if (!TextComment || TextComment->empty()) { | ||
| ChildrenIt = ChildrenArray.erase(ChildrenIt); | ||
| continue; | ||
| } | ||
| ++ChildrenIt; | ||
| } | ||
| return ChildrenArray; | ||
| } | ||
|
|
||
| static json::Value extractVerbatimComments(json::Array VerbatimLines) { | ||
|
|
@@ -131,7 +166,8 @@ static Object serializeComment(const CommentInfo &I, Object &Description) { | |
|
|
||
| switch (I.Kind) { | ||
| case CommentKind::CK_TextComment: { | ||
| Obj.insert({commentKindToString(I.Kind), I.Text}); | ||
| if (!I.Text.empty()) | ||
| Obj.insert({commentKindToString(I.Kind), I.Text}); | ||
| return Obj; | ||
| } | ||
|
|
||
|
|
@@ -265,6 +301,9 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, | |
| if (auto *ParagraphComment = Comment.getAsObject(); | ||
| ParagraphComment->get("ParagraphComment")) { | ||
| auto TextCommentsArray = extractTextComments(ParagraphComment); | ||
| if (TextCommentsArray.kind() == json::Value::Null || | ||
| TextCommentsArray.getAsArray()->empty()) | ||
| continue; | ||
| insertComment(Description, TextCommentsArray, "ParagraphComments"); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this equivalent? Am I missing something?