Skip to content

Commit

Permalink
add types
Browse files Browse the repository at this point in the history
  • Loading branch information
faraazahmad committed Dec 18, 2023
1 parent 60cc1fe commit abe9229
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit abe9229

Please sign in to comment.