Skip to content

Commit fed0477

Browse files
authored
Merge pull request #93 from r7kamura/feature/family
Use more consistent name on Node family API
2 parents bb8cb82 + a2a10b0 commit fed0477

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

lib/rucoa/handlers/text_document_document_highlight_handler.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def global_variable_scopable_node
300300
def nodes
301301
return [] unless global_variable_scopable_node
302302

303-
global_variable_scopable_node.each_descendant(:gvar, :gvasgn).select do |node|
303+
global_variable_scopable_node.each_descendant_node(:gvar, :gvasgn).select do |node|
304304
node.name == @node.name
305305
end
306306
end
@@ -331,7 +331,7 @@ def instance_variable_scopable_node
331331
def nodes
332332
return [] unless instance_variable_scopable_node
333333

334-
instance_variable_scopable_node.each_descendant(:ivar, :ivasgn).select do |node|
334+
instance_variable_scopable_node.each_descendant_node(:ivar, :ivasgn).select do |node|
335335
node.name == @node.name
336336
end
337337
end
@@ -361,7 +361,7 @@ def instance_variable_scopable_node
361361
def nodes
362362
return [] unless instance_variable_scopable_node
363363

364-
instance_variable_scopable_node.each_descendant(:cvar, :cvasgn).select do |node|
364+
instance_variable_scopable_node.each_descendant_node(:cvar, :cvasgn).select do |node|
365365
node.name == @node.name
366366
end
367367
end
@@ -410,10 +410,10 @@ def assignment_node
410410
end
411411
break target if target
412412
else
413-
target = node.previous_siblings.reverse.find do |sibling|
413+
target = node.previous_sibling_nodes.reverse.find do |sibling_node|
414414
lvasgn_node = [
415-
sibling,
416-
*sibling.descendants
415+
sibling_node,
416+
*sibling_node.descendant_nodes
417417
].reverse.find do |sibling_or_sibling_descendant|
418418
case sibling_or_sibling_descendant
419419
when Nodes::LvasgnNode
@@ -452,11 +452,11 @@ def reference_nodes
452452
[assignment_node] + assignment_node.ancestors.take_while do |node|
453453
!SCOPE_BOUNDARY_NODE_TYPES.include?(node.type)
454454
end
455-
).flat_map(&:next_siblings)
455+
).flat_map(&:next_sibling_nodes)
456456
end.flat_map do |node|
457457
[
458458
node,
459-
*node.descendants
459+
*node.descendant_nodes
460460
]
461461
end.take_while do |node| # FIXME: flat_map and take_while are not correct solution for shadowing.
462462
case node

lib/rucoa/nodes/base.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def child_nodes
2525
end
2626

2727
# @return [Array<Rucoa::Nodes::Base>]
28-
def descendants
29-
each_descendant.to_a
28+
def descendant_nodes
29+
each_descendant_node.to_a
3030
end
3131

3232
# @param types [Array<Symbol>]
@@ -58,13 +58,13 @@ def each_child_node(
5858
# @param types [Array<Symbol>]
5959
# @return [Rucoa::Nodes::Base] if a block is given
6060
# @return [Enumerator] if no block is given
61-
def each_descendant(
61+
def each_descendant_node(
6262
*types,
6363
&block
6464
)
6565
return to_enum(__method__, *types) unless block
6666

67-
visit_descendants(types, &block)
67+
visit_descendant_nodes(types, &block)
6868
self
6969
end
7070

@@ -150,11 +150,11 @@ def namespace
150150
# line: 4
151151
# )
152152
# )
153-
# expect(node.next_siblings.map(&:name)).to eq(%w[d e])
154-
def next_siblings
153+
# expect(node.next_sibling_nodes.map(&:name)).to eq(%w[d e])
154+
def next_sibling_nodes
155155
return [] unless parent
156156

157-
parent.child_nodes[(sibling_index + 1)..]
157+
parent.child_nodes[(sibling_node_index + 1)..]
158158
end
159159

160160
# @return [Rucoa::Nodes::Base, nil]
@@ -186,11 +186,11 @@ def parent=(node)
186186
# line: 4
187187
# )
188188
# )
189-
# expect(node.previous_siblings.map(&:name)).to eq(%w[a b])
190-
def previous_siblings
189+
# expect(node.previous_sibling_nodes.map(&:name)).to eq(%w[a b])
190+
def previous_sibling_nodes
191191
return [] unless parent
192192

193-
parent.child_nodes[0...sibling_index]
193+
parent.child_nodes[0...sibling_node_index]
194194
end
195195

196196
# @note Override.
@@ -212,23 +212,23 @@ def updated(
212212

213213
protected
214214

215-
# Visit all descendants.
215+
# Visit all descendant_nodes.
216216
# @param types [Array<Symbol>]
217217
# @return [void]
218-
def visit_descendants(
218+
def visit_descendant_nodes(
219219
types,
220220
&block
221221
)
222222
each_child_node do |child|
223223
yield(child) if types.empty? || types.include?(child.type)
224-
child.visit_descendants(types, &block)
224+
child.visit_descendant_nodes(types, &block)
225225
end
226226
end
227227

228228
private
229229

230230
# @return [Integer, nil]
231-
def sibling_index
231+
def sibling_node_index
232232
parent&.child_nodes&.index do |child|
233233
child.equal?(self)
234234
end

lib/rucoa/source.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def parse_result
122122
def root_and_descendant_nodes
123123
return [] unless root_node
124124

125-
[root_node, *root_node.descendants]
125+
[root_node, *root_node.descendant_nodes]
126126
end
127127

128128
# @return [URI]

lib/rucoa/yard/definitions_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def initialize(
3535
def call
3636
[
3737
@root_node,
38-
*@root_node.descendants
38+
*@root_node.descendant_nodes
3939
].flat_map do |node|
4040
[
4141
DefinitionGenerators::ClassDefinitionGenerator,

0 commit comments

Comments
 (0)