Stop accepting Document objects as CodeObject#comment#1210
Merged
st0012 merged 3 commits intoruby:masterfrom Jan 28, 2025
Merged
Stop accepting Document objects as CodeObject#comment#1210st0012 merged 3 commits intoruby:masterfrom
Document objects as CodeObject#comment#1210st0012 merged 3 commits intoruby:masterfrom
Conversation
523622d to
7a297e8
Compare
st0012
reviewed
Nov 30, 2024
Member
st0012
left a comment
There was a problem hiding this comment.
Since this is a potentially risky change and we don't have much time to test it in another release, I'll wait for Ruby 3.4's release before merging it.
Comment on lines
+64
to
+70
| if comment.is_a?(Array) | ||
| comment.each do |c| | ||
| @comments << extract_comment(c) | ||
| end | ||
| else | ||
| raise TypeError, "unknown comment type: #{comment.inspect}" | ||
| comment = extract_comment(comment) | ||
| @comments << comment unless comment.empty? |
Member
There was a problem hiding this comment.
Can it be further simplified to something like:
comments = Array(comment)
comments.each do |c|
extracted_comment = extract_comment(comment)
@comments << extracted_comment unless extracted_comment.empty?
end| end | ||
| else | ||
| raise RDoc::Error, "BUG: unknown comment class #{@comments.class}" | ||
| @comments.map do |comment| |
| end | ||
| else | ||
| raise RDoc::Error, "BUG: unknown comment class #{@comments.class}" | ||
| @comments.delete_if do |my_comment| |
Member
There was a problem hiding this comment.
Can we also rename these locals to something like stored_comment and target_comment?
@comments.delete_if do |stored_comment|
stored_comment.file == target_comment.file
end| formatter.start_accepting | ||
| formatter.accept_document(content) | ||
| formatter.end_accepting | ||
| comment.text |
Member
There was a problem hiding this comment.
Thank you for simplifying this part too ❤️
ed4589e to
ad62c57
Compare
…ect.comment CodeObject#comment is normally String or Comment, but Marshal.dump and load creates CodeObject with comment=Document. Some method requires Document stored in CodeObject#comment, some requires Comment. We should stop mixing Document with Comment because it is mixing huge complexity and potential bugs to RDoc codebase.
ad62c57 to
4955198
Compare
Document objects as CodeObject#comment
Document objects as CodeObject#commentDocument objects as CodeObject#comment
st0012
approved these changes
Jan 28, 2025
Member
st0012
left a comment
There was a problem hiding this comment.
Sorry for the delay and thanks for the great improvement 👍
I've tested this with ruby/ruby and rails/sdoc, which AFAIK are the 2 biggest users of RDoc atm, and both worked fine with it.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CodeObject#commentis normally String or Comment, but Marshal dump and load creates CodeObject with Document as a comment. So there are two types of CodeObject that shouldn't be mixed:This is implicitly doubling the number of total classes in RDoc. It is mixing huge complexity and potential bugs to RDoc codebase. Some method only accepts ParsedCodeObject. Some method only accepts MarshalLoadedCodeObject. It is difficult to know.
It looks like document is assigned to comment to represent parse-result-cached comment. Alternatively,
Comment#document=can be used to represent it.Ideally, we should avoid mixing String with Comment, but String it is too frequently used. I think it will be easy to remove mixing String after switching to PrismRuby Parser.
I believe we should do this refactor someday but maybe not before Ruby 3.4 because the release date is pretty close.