Class: RubyLsp::Rails::FactoryBot::Addon

Inherits:
Addon
  • Object
show all
Defined in:
lib/ruby_lsp/rails/factory_bot/addon.rb

Instance Method Summary collapse

Instance Method Details

#activate(global_state) ⇒ Object



14
15
16
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 14

def activate(global_state, *)
  @ruby_index = global_state.index
end

#create_completion_listener(response_builder, node_context, dispatcher, uri) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 24

def create_completion_listener(response_builder, node_context, dispatcher, uri)
  path = uri.to_standardized_path
  return unless path&.end_with?("_test.rb") || path&.end_with?("_spec.rb")
  return unless factory_bot_call_args?(node_context)

  Completion.new(response_builder, node_context, dispatcher, RubyLsp::Rails::RunnerClient.instance)
end

#create_hover_listener(response_builder, node_context, dispatcher) ⇒ Object



32
33
34
35
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 32

def create_hover_listener(response_builder, node_context, dispatcher)
  # TODO: need URI param
  Hover.new(response_builder, node_context, dispatcher, RubyLsp::Rails::RunnerClient.instance, @ruby_index)
end

#deactivateObject



18
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 18

def deactivate(*); end

#nameObject



20
21
22
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 20

def name
  "ruby-lsp-rails-factory-bot"
end

#workspace_did_change_watched_files(changes) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ruby_lsp/rails/factory_bot/addon.rb', line 37

def workspace_did_change_watched_files(changes)
  return unless changes.any? do |change|
    change[:uri].match?(/(?:spec|test).+factor.+\.rb/)
  end

  RubyLsp::Rails::RunnerClient.instance.trigger_reload
end