115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/ast/crispr/ruby/prism.rb', line 115
def (start_text:, end_text:, id: nil, limit: nil, span: :nearest,
include_trailing_gap: false, metadata: {}, **options)
Ast::Crispr::OwnerSelector.new(
id: id || "ruby_comment_line_block_#{start_text}",
limit: limit,
metadata: metadata.merge(
adapter: Ast::Crispr::Ruby::Prism.adapter,
owner_scope: :ruby_comments,
selector_kind: :ruby_comment_line_block,
selection_intent: :line_marker_block,
include_trailing_gap: include_trailing_gap
).merge(options),
locate: lambda do |context|
= context.structural_owners(owner_scope: :ruby_comments)
if span.to_sym == :outermost
opening = .find do ||
context.location_slice(.location).rstrip == start_text.to_s
end
closing = .reverse.find do ||
opening &&
context.location_slice(.location).rstrip == end_text.to_s &&
.location.end_line >= opening.location.start_line
end
next [] unless opening && closing
end_line = closing.location.end_line
end_line = context.expand_following_gap(end_line) if include_trailing_gap
next [
Ast::Crispr::Match.new(
node: opening,
start_line: opening.location.start_line,
end_line: end_line,
metadata: {
start_boundary: :comment_region_start,
end_boundary: (include_trailing_gap ? :owner_end_plus_trailing_gap : :owner_end),
payload_kind: :comment_owned_body,
start_text: start_text,
end_text: end_text
}
)
]
end
.each_with_index.filter_map do |, index|
next unless context.location_slice(.location).rstrip == start_text.to_s
closing = [index + 1..]&.find do |candidate|
context.location_slice(candidate.location).rstrip == end_text.to_s
end
next unless closing
end_line = closing.location.end_line
end_line = context.expand_following_gap(end_line) if include_trailing_gap
Ast::Crispr::Match.new(
node: ,
start_line: .location.start_line,
end_line: end_line,
metadata: {
start_boundary: :comment_region_start,
end_boundary: (include_trailing_gap ? :owner_end_plus_trailing_gap : :owner_end),
payload_kind: :comment_owned_body,
start_text: start_text,
end_text: end_text
}
)
end
end
)
end
|