Skip to content

Commit fc96615

Browse files
authored
Index ConstantAndWrite and ConstantOperatorWrite (#1049)
1 parent 4dde9cb commit fc96615

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/ruby_indexer/lib/ruby_indexer/visitor.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def visit(node)
3535
add_index_entry(node, Index::Entry::Class)
3636
when YARP::ModuleNode
3737
add_index_entry(node, Index::Entry::Module)
38-
when YARP::ConstantWriteNode, YARP::ConstantOrWriteNode
38+
when YARP::ConstantWriteNode, YARP::ConstantOrWriteNode, YARP::ConstantAndWriteNode,
39+
YARP::ConstantOperatorWriteNode
3940
name = fully_qualify_name(node.name.to_s)
4041
add_constant(node, name)
4142
when YARP::ConstantPathWriteNode, YARP::ConstantPathOrWriteNode, YARP::ConstantPathOperatorWriteNode,
@@ -90,6 +91,8 @@ def handle_private_constant(node)
9091
node: T.any(
9192
YARP::ConstantWriteNode,
9293
YARP::ConstantOrWriteNode,
94+
YARP::ConstantAndWriteNode,
95+
YARP::ConstantOperatorWriteNode,
9396
YARP::ConstantPathWriteNode,
9497
YARP::ConstantPathOrWriteNode,
9598
YARP::ConstantPathOperatorWriteNode,

lib/ruby_indexer/test/constant_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,23 @@ module A
306306
constant = @index["A::M"].first
307307
assert_instance_of(Index::Entry::Constant, constant)
308308
end
309+
310+
def test_indexing_or_and_operator_nodes
311+
index(<<~RUBY)
312+
A ||= 1
313+
B &&= 2
314+
C &= 3
315+
D::E ||= 4
316+
F::G &&= 5
317+
H::I &= 6
318+
RUBY
319+
320+
assert_entry("A", Index::Entry::Constant, "/fake/path/foo.rb:0-0:0-7")
321+
assert_entry("B", Index::Entry::Constant, "/fake/path/foo.rb:1-0:1-7")
322+
assert_entry("C", Index::Entry::Constant, "/fake/path/foo.rb:2-0:2-6")
323+
assert_entry("D::E", Index::Entry::Constant, "/fake/path/foo.rb:3-0:3-10")
324+
assert_entry("F::G", Index::Entry::Constant, "/fake/path/foo.rb:4-0:4-10")
325+
assert_entry("H::I", Index::Entry::Constant, "/fake/path/foo.rb:5-0:5-9")
326+
end
309327
end
310328
end

0 commit comments

Comments
 (0)