- Notifications
You must be signed in to change notification settings - Fork 470
Add docCommentValue property to Trivia for cleaned comments#2966
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Conversation
ahoppen left a comment
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.
Thanks for addressing the issue, @zyadtaha. I think the PR still needs some polishing regarding indentation handling. I left a few comments inline.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
3ad450f to c23e3dcComparezyadtaha commented Feb 16, 2025
Thanks for the feedback, @ahoppen! I've addressed the comments—let me know if anything else needs attention. |
ahoppen left a comment
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.
Thanks for the adjustments. I left a few more edge cases to consider as comments.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
c23e3dc to 04f700eComparezyadtaha commented Feb 25, 2025
Hey @ahoppen, just wanted to check if there's anything else needed from my side on this PR. Let me know if you have any concerns. Thanks! |
ahoppen left a comment
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.
Thanks for the updates. I think there are still a few more issues that need to be addressed.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
zyadtaha commented Apr 14, 2025
Hey @ahoppen, I've pushed my updates. For your last two comments, I've added responses—let me know your feedback when you get a chance. Thanks! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
8df001d to 52fdc83CompareUh oh!
There was an error while loading. Please reload this page.
ahoppen commented Apr 23, 2025
I addressed my own review comments in a 2197103, which I pushed to your branch. Could you check if these changes make sense to you? |
zyadtaha commented Apr 25, 2025
Thank you! I pulled the changes and reviewed the new logic and tests, and everything looks great to me. I really appreciated the detailed doc comments; they helped me understand your approach much better. I also liked how you split the tests into separate functions since it makes things much clearer. I just had one question: why did you move the Also, if you have any feedback on my code, communication, or anything I could improve, I’d be very grateful. I want to make sure I’m not wasting your time and that I'm learning as much as possible through this process. |
ahoppen commented Apr 29, 2025
Thanks for checking that the changes look good to you.
The implementation of
You did great work to get things started. I just figured that it was easier to fix the edge cases instead of repeatedly pointing out edge cases and then discovering more after you addressed them. Thinking of all possible edge cases is a big part of developing compiler-related tooling and it’s hard to teach that general way of thinking in pull request comments. |
rintaro left a comment
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.
I'm not sure about concatenating the pieces. The current behavior sounds fragile and not predictable.
TriviaPiece.commentValue: String? (as #1890 requested) would make more sense and we should implement that at least. But it's also debatable what to do with the space after //.
Trivia.commentValue: String? should be IMO a high-level API based on TriviaPiece.commentValue, but the concatenating behavior mixing trivia kinds should be discussed more.
Maybe Trivia.docCommentValue: String? that would only handle .docLineComment/.docBlockComment makes more sense.
| } | ||
| comments.append(processedText[...]) | ||
| case.lineComment(let text),.docLineComment(let text): | ||
| if hasBlockComment { |
rintaroApr 29, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Here we allow
/// Foo Bar /// This is a doc-comment. // @_spi(Testing) public fooBar(){}resulting "Foo Bar\nThis is a doc-comment\n@_spi(Testing)", but not
/** * Foo Bar * This is a doc-comment. */ // @_spi(Testing) public fooBar(){}Not sure about this case.
zyadtaha commented May 3, 2025
I appreciate the thoughtful feedback! I agree that
Your suggestion of |
ahoppen commented May 6, 2025
@Rinataro and I just chatted about this and agreed that it would be best if we focus on The doc line comment should return the value of the last doc comment that’s inside the
/// not included /// included /// also included func test(){} /// not included // /// included func test(){} /// not included /* abc */ /// included func test(){} /** not included */ /// included func test(){} /// included // ignored func test(){}
|
commentValue property to Trivia for cleaned commentsdocCommentValue property to Trivia for cleaned commentszyadtaha commented Jun 12, 2025
Hi @ahoppen and @rintaro, I've just pushed my latest changes. The implementation now handles concatenation for doc block comments as the compiler does. If no doc block comments are found, it falls back to returning the last consecutive block of doc line comments. Please let me know if there are any new details! |
ahoppen left a comment
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.
No worries for the time gap. I hope your exams went well.
Thanks for continuing to work on this PR. Things are looking good to me, I just left a few minor comments inline.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e52a2b3 to b9cdf8bCompare
ahoppen left a comment
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.
Nice work. Just came back to this and this is looking really good. One super minor comment and one open question about how the API should behave.
Could you also format your changes as described in https://github.com/swiftlang/swift-syntax/blob/main/CONTRIBUTING.md#formatting?
| /// Keep track of whether we have seen a line or block comment trivia piece. | ||
| varhasBlockComment=false | ||
| varcurrentLineComments:[Substring]=[] |
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.
This could now be of type [String], right? We don’t ever add substrings to this array if I understand correctly.
| switch piece { | ||
| case.docBlockComment(let text): | ||
| iflet processedComment =processBlockComment(text){ | ||
| if hasBlockComment { |
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.
Do we need the variable hasBlockComment? If I understand correctly, we never set it to false and if it’s false then we always have comments == [], which means that the else-block is equivalent to this if branch.
| assertCommentValue( | ||
| """ | ||
| /** abc */ | ||
| /** def */ | ||
| """, | ||
| docCommentValue:"abc\ndef") |
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.
Sorry in case we discussed this before and I just don’t remember but my gut feeling is that the result of this should be def, not abc\ndef. @rintaro What do you think?
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.
I vote for def, i.e. only use the last block doc-comment.
FWIW, the current SourceKit seems to concat them as long as there's no blank lines between them, but that's also true for this case.
/** not included */ /// included
This PR continues the work from #2578, addressing the review comments and refining the behavior of
Trivia.commentValue.