File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -100,18 +100,14 @@ def nearest_targets(node, comment)
100
100
comment_end = comment . location . end_offset
101
101
102
102
targets = [ ]
103
- node . deconstruct_keys ( nil ) . each do |key , value |
104
- next if key == :location
105
-
103
+ node . comment_targets . map do |value |
106
104
case value
107
105
when StatementsNode
108
106
targets . concat ( value . body . map { |node | NodeTarget . new ( node ) } )
109
107
when Node
110
108
targets << NodeTarget . new ( value )
111
109
when Location
112
110
targets << LocationTarget . new ( value )
113
- when Array
114
- targets . concat ( value . map { |node | NodeTarget . new ( node ) } ) if value . first . is_a? ( Node )
115
111
end
116
112
end
117
113
@@ -166,6 +162,8 @@ def nearest_targets(node, comment)
166
162
end
167
163
end
168
164
165
+ private_constant :Comments
166
+
169
167
# Attach the list of comments to their respective locations in the tree.
170
168
def attach_comments!
171
169
Comments . new ( self ) . attach!
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class ParseResult
17
17
# Note that the logic in this file should be kept in sync with the Java
18
18
# MarkNewlinesVisitor, since that visitor is responsible for marking the
19
19
# newlines for JRuby/TruffleRuby.
20
- class MarkNewlinesVisitor < Visitor
20
+ class Newlines < Visitor
21
21
def initialize ( newline_marked )
22
22
@newline_marked = newline_marked
23
23
end
@@ -50,12 +50,11 @@ def visit_statements_node(node)
50
50
end
51
51
end
52
52
53
- private_constant :MarkNewlinesVisitor
53
+ private_constant :Newlines
54
54
55
55
# Walk the tree and mark nodes that are on a new line.
56
56
def mark_newlines!
57
- newline_marked = Array . new ( 1 + source . offsets . size , false )
58
- value . accept ( MarkNewlinesVisitor . new ( newline_marked ) )
57
+ value . accept ( Newlines . new ( Array . new ( 1 + source . offsets . size , false ) ) )
59
58
end
60
59
end
61
60
end
Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ module YARP
48
48
} . compact . join ( ", " ) %> ]
49
49
end
50
50
51
+ # def comment_targets: () -> Array[Node | Location]
52
+ def comment_targets
53
+ [<%= node . fields . map { |field |
54
+ case field
55
+ when YARP ::NodeField , YARP ::LocationField then field . name
56
+ when YARP ::OptionalNodeField , YARP ::NodeListField , YARP ::OptionalLocationField then "*#{ field . name } "
57
+ end
58
+ } . compact . join ( ", " ) %> ]
59
+ end
60
+
51
61
# def copy: (**params) -> <%= node . name %>
52
62
def copy(**params)
53
63
<%= node . name %> .new(
You can’t perform that action at this time.
0 commit comments