diff --git a/lib/spoom/deadcode/index.rb b/lib/spoom/deadcode/index.rb index 670dfdf0..f8dd079e 100644 --- a/lib/spoom/deadcode/index.rb +++ b/lib/spoom/deadcode/index.rb @@ -60,6 +60,15 @@ def finalize!(plugins: []) ) define(definition) plugins.each { |plugin| plugin.internal_on_define_module(symbol_def, definition) } + when Model::Constant + definition = Definition.new( + kind: Definition::Kind::Constant, + name: symbol.name, + full_name: symbol.full_name, + location: symbol_def.location, + ) + define(definition) + plugins.each { |plugin| plugin.internal_on_define_constant(symbol_def, definition) } end end end diff --git a/lib/spoom/deadcode/indexer.rb b/lib/spoom/deadcode/indexer.rb index eedd35c5..0edec1c6 100644 --- a/lib/spoom/deadcode/indexer.rb +++ b/lib/spoom/deadcode/indexer.rb @@ -158,20 +158,7 @@ def visit_constant_path_node(node) sig { override.params(node: Prism::ConstantPathWriteNode).void } def visit_constant_path_write_node(node) - const_path_node = node.target - parent = const_path_node.parent - name = const_path_node.name.to_s - - if parent - visit(parent) - - parent_name = parent.slice - full_name = [*@names_nesting, parent_name, name].compact.join("::") - define_constant(name, full_name, node) - else - define_constant(name, name, node) - end - + visit(node.target.parent) visit(node.value) end @@ -182,9 +169,6 @@ def visit_constant_read_node(node) sig { override.params(node: Prism::ConstantWriteNode).void } def visit_constant_write_node(node) - name = node.name.to_s - full_name = [*@names_nesting, name].join("::") - define_constant(name, full_name, node) visit(node.value) end @@ -257,9 +241,6 @@ def visit_module_node(node) def visit_multi_write_node(node) node.lefts.each do |const| case const - when Prism::ConstantTargetNode, Prism::ConstantPathTargetNode - name = const.slice - define_constant(T.must(name.split("::").last), [*@names_nesting, name].join("::"), const) when Prism::LocalVariableTargetNode reference_method("#{const.name}=", node) end @@ -345,18 +326,6 @@ def define_attr_writer(name, full_name, node) @plugins.each { |plugin| plugin.internal_on_define_accessor(self, definition) } end - sig { params(name: String, full_name: String, node: Prism::Node).void } - def define_constant(name, full_name, node) - definition = Definition.new( - kind: Definition::Kind::Constant, - name: name, - full_name: full_name, - location: node_location(node), - ) - @index.define(definition) - @plugins.each { |plugin| plugin.internal_on_define_constant(self, definition) } - end - sig { params(name: String, full_name: String, node: Prism::Node).void } def define_method(name, full_name, node) definition = Definition.new(