Class: RubyLsp::RailsRoutes::Addon

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

Overview

Ruby LSP add-on that adds go-to-definition from *_path / *_url route helpers to the controller action the named route maps to. Works alongside ruby-lsp-rails, whose own Definition listener contributes the routes.rb declaration; this add-on only adds the action location as an extra candidate.

Constant Summary collapse

SERVER_ADDON_NAME =
"Rails Routes"

Instance Method Summary collapse

Instance Method Details

#activate(_global_state, _outgoing_queue) ⇒ Object



19
20
21
# File 'lib/ruby_lsp/ruby_lsp_rails_routes/addon.rb', line 19

def activate(_global_state, _outgoing_queue)
  @server_addon_registered = false
end

#create_definition_listener(response_builder, _uri, node_context, dispatcher) ⇒ Object

Invoked on every definition request. The ruby-lsp-rails client is resolved lazily here (not in #activate) because add-on activation order is not guaranteed, and because the runner client boots asynchronously — it is a NullClient until ready.



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

def create_definition_listener(response_builder, _uri, node_context, dispatcher)
  client = rails_runner_client
  return unless client

  ensure_server_addon_registered(client)

  Definition.new(client, SERVER_ADDON_NAME, response_builder, node_context, dispatcher)
end

#deactivateObject



23
# File 'lib/ruby_lsp/ruby_lsp_rails_routes/addon.rb', line 23

def deactivate; end

#nameObject



25
26
27
# File 'lib/ruby_lsp/ruby_lsp_rails_routes/addon.rb', line 25

def name
  "Rails Routes"
end

#versionObject



29
30
31
# File 'lib/ruby_lsp/ruby_lsp_rails_routes/addon.rb', line 29

def version
  VERSION
end