Skip to content

Commit

Permalink
Deadcode Indexer relies on Model for constant definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Terrasa <[email protected]>
  • Loading branch information
Morriar committed Jun 20, 2024
1 parent 2fca5fd commit d8af777
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
9 changes: 9 additions & 0 deletions lib/spoom/deadcode/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 1 addition & 32 deletions lib/spoom/deadcode/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d8af777

Please sign in to comment.