Class: RubyLsp::Rails::FactoryBot::Definition

Inherits:
Object
  • Object
show all
Includes:
RubyLsp::Requests::Support::Common
Defined in:
lib/ruby_lsp/rails/factory_bot/definition.rb

Overview

Definition listener - calls the registered methods when the appropriate nodes are entered

Instance Method Summary collapse

Constructor Details

#initialize(response_builder, node_context, dispatcher, server_client) ⇒ Definition

Returns a new instance of Definition.



14
15
16
17
18
19
20
# File 'lib/ruby_lsp/rails/factory_bot/definition.rb', line 14

def initialize(response_builder, node_context, dispatcher, server_client)
  @response_builder = response_builder
  @node_context = node_context
  @server_client = server_client

  dispatcher.register self, :on_symbol_node_enter
end

Instance Method Details

#on_symbol_node_enter(symbol_node) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ruby_lsp/rails/factory_bot/definition.rb', line 22

def on_symbol_node_enter(symbol_node)
  parent = @node_context.parent
  call_node = @node_context.call_node

  return unless call_node

  # "parent" isn't strictly speaking the immediate parent as in the AST - the
  # element it refers to is a bit opinionated... in this case, it is always the call node,
  # whether the symbol is an argument in the call_node args, or a symbol in a kw hash :/
  unless parent.is_a?(Prism::CallNode) || FactoryBot::FACTORY_BOT_METHODS.include?(call_node.message.to_sym)
    return
  end

  process_arguments_pattern(symbol_node, call_node.arguments.arguments)
end