Skip to content

Commit

Permalink
add RubyLsp::Rails module
Browse files Browse the repository at this point in the history
  • Loading branch information
faraazahmad committed Dec 18, 2023
1 parent 77da138 commit e3f748f
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions lib/ruby_lsp/ruby_lsp_rails/schema_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
# frozen_string_literal: true

module RubyLsp
class SchemaCollector < Prism::Visitor
extend T::Sig
module Rails
class SchemaCollector < Prism::Visitor
extend T::Sig

sig { returns(T::Hash[String, Prism::Location]) }
attr_reader :tables
sig { returns(T::Hash[String, Prism::Location]) }
attr_reader :tables

sig { void }
def initialize
@tables = {}
sig { void }
def initialize
@tables = {}

super
end
super
end

sig { params(node: Prism::CallNode).void }
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
Expand Down

0 comments on commit e3f748f

Please sign in to comment.