Class: RubyLsp::Rails::FactoryBot::Hover

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

Overview

Hover 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, ruby_index) ⇒ Hover

Returns a new instance of Hover.



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

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

  dispatcher.register self, :on_symbol_node_enter
end

Instance Method Details

#on_symbol_node_enter(symbol_node) ⇒ Object



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

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