lib/spoom/deadcode/indexer.rb in spoom-1.2.2 vs lib/spoom/deadcode/indexer.rb in spoom-1.2.3

- old
+ new

@@ -10,18 +10,19 @@ attr_reader :path, :file_name sig { returns(Index) } attr_reader :index - sig { params(path: String, source: String, index: Index).void } - def initialize(path, source, index) + sig { params(path: String, source: String, index: Index, plugins: T::Array[Plugins::Base]).void } + def initialize(path, source, index, plugins: []) super() @path = path @file_name = T.let(File.basename(path), String) @source = source @index = index + @plugins = plugins @previous_node = T.let(nil, T.nilable(SyntaxTree::Node)) @names_nesting = T.let([], T::Array[String]) @nodes_nesting = T.let([], T::Array[SyntaxTree::Node]) @in_const_field = T.let(false, T::Boolean) @in_opassign = T.let(false, T::Boolean) @@ -226,10 +227,14 @@ full_name = [*@names_nesting, name].join("::") define_attr_reader(name, full_name, arg) define_attr_writer("#{name}=", "#{full_name}=", arg) end else + @plugins.each do |plugin| + plugin.on_send(self, send) + end + reference_method(send.name, send.node) visit_all(send.args) visit(send.block) end end @@ -268,12 +273,10 @@ sig { override.params(node: SyntaxTree::VCall).void } def visit_vcall(node) visit_send(Send.new(node: node, name: node_string(node.value))) end - private - # Definition indexing sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_attr_reader(name, full_name, node) definition = Definition.new( @@ -281,10 +284,11 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_accessor(self, definition) } end sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_attr_writer(name, full_name, node) definition = Definition.new( @@ -292,10 +296,11 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_accessor(self, definition) } end sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_class(name, full_name, node) definition = Definition.new( @@ -303,10 +308,11 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_class(self, definition) } end sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_constant(name, full_name, node) definition = Definition.new( @@ -314,10 +320,11 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_constant(self, definition) } end sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_method(name, full_name, node) definition = Definition.new( @@ -325,10 +332,11 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_method(self, definition) } end sig { params(name: String, full_name: String, node: SyntaxTree::Node).void } def define_module(name, full_name, node) definition = Definition.new( @@ -336,9 +344,10 @@ name: name, full_name: full_name, location: node_location(node), ) @index.define(definition) + @plugins.each { |plugin| plugin.on_define_module(self, definition) } end # Reference indexing sig { params(name: String, node: SyntaxTree::Node).void }