diff --git a/lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb b/lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb index 00357467..e56515ef 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb @@ -1,21 +1,31 @@ -class SchemaCollector < Prism::Visitor - attr_reader :tables +# typed: strict +# frozen_string_literal: true - def initialize - @tables = {} +module RubyLsp + class SchemaCollector < Prism::Visitor + extend T::Sig - super - end + sig { returns(T::Hash(String, Prism::Location)) } + attr_reader :tables + + sig { void } + def initialize + @tables = {} + + super + end - def visit_call_node(node) - return if node.block.nil? + sig { params(node: Prism::CallNode).void } + def visit_call_node(node) + return if node.block.nil? - node.block.body.child_nodes.each do |child_node| - next unless child_node.is_a?(Prism::CallNode) - next unless child_node.name == :create_table + node.block.body.child_nodes.each do |child_node| + next unless child_node.is_a?(Prism::CallNode) + next unless child_node.name == :create_table - table_name = child_node.arguments.child_nodes.first.content - @tables[table_name.classify] = child_node.location + table_name = child_node.arguments.child_nodes.first.content + @tables[table_name.classify] = child_node.location + end end end end