Ruby LSPで通常解決できないRailsの動的なViewヘルパーとController DSLを、実行時のsource_locationから定義元へ案内するアドオンです。
以下のような呼び出しから、gem内の定義へジャンプできます。
<%= javascript_importmap_tags %>class ApplicationController < ActionController::Base
stale_when_importmap_changes
endGitHubリポジトリから利用する場合は、RailsプロジェクトのGemfileへ追加します。
group :development do
gem "ruby-lsp-rails-runtime-definitions",
github: "return-nil/ruby-lsp-rails-runtime-definitions",
require: false
endbundle install後にRuby LSPまたはエディタを再起動してください。
通常のRuby LSPが定義を返さなかった場合だけ、Ruby LSP Railsが起動しているRailsプロセスへ問い合わせます。
- ERBでは
ApplicationController.helpers.method(name).source_locationを使用します。 - Controllerでは現在のControllerクラスの
method(name).source_locationを使用します。 - 定義ジャンプ時だけ問い合わせるため、入力中の解析処理には追加負荷をかけません。
- Ruby 3.0以上
- Ruby LSP 0.26.x
- Ruby LSP Rails 0.4.x
Ruby LSPのアドオンAPIはexperimentalです。対応範囲外のバージョンではアドオンを読み込みません。
bundle install
bundle exec rake