diff --git a/lib/ruby_lsp/ruby_lsp_rails/addon.rb b/lib/ruby_lsp/ruby_lsp_rails/addon.rb index f488c034..1836ba28 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/addon.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/addon.rb @@ -123,6 +123,10 @@ def workspace_did_change_watched_files(changes) change[:uri].end_with?("db/schema.rb") || change[:uri].end_with?("structure.sql") end @rails_runner_client.trigger_reload + elsif changes.any? do |change| + change[:uri].end_with?("routes.rb") # TODO: handle other patterns + end + @rails_runner_client.reload_routes end end @@ -141,7 +145,7 @@ def register_additional_file_watchers(global_state:, outgoing_queue:) register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new( watchers: [ Interface::FileSystemWatcher.new( - glob_pattern: "**/*structure.sql", + glob_pattern: "**/*structure.sql,**/*routes.rb", kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE, ), ], diff --git a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb index 10706648..7535d702 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb @@ -225,6 +225,18 @@ def trigger_reload nil end + sig { void } + def reload_routes + log_message("Reloading Rails routes") + send_notification("reload_routes") + rescue IncompleteMessageError + log_message( + "Ruby LSP Rails failed to reload routes", + type: RubyLsp::Constant::MessageType::ERROR, + ) + nil + end + sig { void } def shutdown log_message("Ruby LSP Rails shutting down server") diff --git a/lib/ruby_lsp/ruby_lsp_rails/server.rb b/lib/ruby_lsp/ruby_lsp_rails/server.rb index 7cad461c..cc5c7562 100644 --- a/lib/ruby_lsp/ruby_lsp_rails/server.rb +++ b/lib/ruby_lsp/ruby_lsp_rails/server.rb @@ -111,6 +111,8 @@ def execute(request, params) send_message(resolve_association_target(params)) when "reload" ::Rails.application.reloader.reload! + when "reload_routes" + ::Rails.application.routes_reloader.execute when "route_location" send_message(route_location(params.fetch(:name))) when "route_info"