Skip to content

Commit

Permalink
Watch for YAML file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jan 17, 2025
1 parent 65bf424 commit 08eaf66
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
26 changes: 20 additions & 6 deletions lib/ruby_lsp/ruby_lsp_rails/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,33 @@ def register_additional_file_watchers(global_state:, outgoing_queue:)
id: "workspace/didChangeWatchedFilesRails",
method: "workspace/didChangeWatchedFiles",
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
watchers: [
Interface::FileSystemWatcher.new(
glob_pattern: "**/*structure.sql",
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
),
],
watchers: [structure_sql_file_watcher, fixture_file_watcher].compact,
),
),
],
),
)
end

sig { returns(Interface::FileSystemWatcher) }
def structure_sql_file_watcher
Interface::FileSystemWatcher.new(
glob_pattern: "**/*structure.sql",
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
)
end

sig { returns(T.nilable(Interface::FileSystemWatcher)) }
def fixture_file_watcher
paths = @rails_runner_client.fixture_paths
return unless paths

Interface::FileSystemWatcher.new(
glob_pattern: "{#{paths.join(",")}}/fixtures/**/*.{yml,yaml,yml.erb,yaml.erb}",
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
)
end

sig { void }
def offer_to_run_pending_migrations
return unless @outgoing_queue
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class EmptyMessageError < MessageError; end
sig { returns(String) }
attr_reader :rails_root

sig { returns(T.nilable(T::Array[String])) }
attr_reader :fixture_paths

sig { params(outgoing_queue: Thread::Queue).void }
def initialize(outgoing_queue)
@outgoing_queue = T.let(outgoing_queue, Thread::Queue)
Expand Down Expand Up @@ -89,6 +92,7 @@ def initialize(outgoing_queue)

initialize_response = T.must(read_response)
@rails_root = T.let(initialize_response[:root], String)
@fixture_paths = T.let(initialize_response[:fixture_paths], T.nilable(T::Array[String]))
log_message("Finished booting Ruby LSP Rails server")

unless ENV["RAILS_ENV"] == "test"
Expand Down
7 changes: 6 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "json"
require "open3"
require "rails/test_help" # to determine the fixture_paths

module RubyLsp
module Rails
Expand Down Expand Up @@ -123,7 +124,11 @@ def initialize(stdout: $stdout, override_default_output_device: true)
def start
load_routes
clear_file_system_resolver_hooks
send_result({ message: "ok", root: ::Rails.root.to_s })
send_result({
message: "ok",
root: ::Rails.root.to_s,
fixture_paths: ActiveSupport::TestCase.fixture_paths,
})

while @running
headers = @stdin.gets("\r\n\r\n")
Expand Down

0 comments on commit 08eaf66

Please sign in to comment.