From 609353085c7acbe353c086046a9cb3d5a155dab0 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Thu, 13 Jun 2024 16:44:13 -0400 Subject: [PATCH] TMP: clean indexer Signed-off-by: Alexandre Terrasa --- lib/spoom/deadcode/indexer.rb | 70 +---------------------------------- 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/lib/spoom/deadcode/indexer.rb b/lib/spoom/deadcode/indexer.rb index ecaa94eb..472cda95 100644 --- a/lib/spoom/deadcode/indexer.rb +++ b/lib/spoom/deadcode/indexer.rb @@ -20,22 +20,10 @@ def initialize(path, source, index, plugins: []) @source = source @index = index @plugins = plugins - @previous_node = T.let(nil, T.nilable(Prism::Node)) - @nodes_nesting = T.let([], T::Array[Prism::Node]) end # Visit - sig { override.params(node: T.nilable(Prism::Node)).void } - def visit(node) - return unless node - - @nodes_nesting << node - super - @nodes_nesting.pop - @previous_node = node - end - sig { override.params(node: Prism::AliasMethodNode).void } def visit_alias_method_node(node) reference_method(node.old_name.slice, node) @@ -219,63 +207,7 @@ def reference_method(name, node) @index.reference(Reference.new(name: name, kind: Reference::Kind::Method, location: node_location(node))) end - # Context - - sig { returns(Prism::Node) } - def current_node - T.must(@nodes_nesting.last) - end - - sig { type_parameters(:N).params(type: T::Class[T.type_parameter(:N)]).returns(T.nilable(T.type_parameter(:N))) } - def nesting_node(type) - @nodes_nesting.reverse_each do |node| - return T.unsafe(node) if node.is_a?(type) - end - - nil - end - - sig { returns(T.nilable(Prism::ClassNode)) } - def nesting_class - nesting_node(Prism::ClassNode) - end - - sig { returns(T.nilable(Prism::BlockNode)) } - def nesting_block - nesting_node(Prism::BlockNode) - end - - sig { returns(T.nilable(Prism::CallNode)) } - def nesting_call - nesting_node(Prism::CallNode) - end - - sig { returns(T.nilable(String)) } - def nesting_class_name - nesting_class = self.nesting_class - return unless nesting_class - - nesting_class.name.to_s - end - - sig { returns(T.nilable(String)) } - def nesting_class_superclass_name - nesting_class_superclass = nesting_class&.superclass - return unless nesting_class_superclass - - nesting_class_superclass.slice.delete_prefix("::") - end - - sig { returns(T.nilable(String)) } - def last_sig - previous_call = @previous_node - return unless previous_call.is_a?(Prism::CallNode) - return unless previous_call.name == :sig - - previous_call.slice - end - - # Node utils + private sig { params(node: Prism::Node).returns(Location) } def node_location(node)