Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Prism::ParseResult::Comments#attach!
attach!
lib/prism/parse_result/comments.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/prism/parse_result/comments.rb, line 84
def attach!
parse_result.comments.each do |comment|
preceding, enclosing, following = nearest_targets(parse_result.value, comment)
target =
if comment.trailing?
preceding || following || enclosing || NodeTarget.new(parse_result.value)
else
# If a comment exists on its own line, prefer a leading comment.
following || preceding || enclosing || NodeTarget.new(parse_result.value)
end
target << comment
end
end
Attach the comments to their respective locations in the tree by mutating the parse result.