Skip to content

Commit 08eaf66

Browse files
committed
Watch for YAML file changes
1 parent 65bf424 commit 08eaf66

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

lib/ruby_lsp/ruby_lsp_rails/addon.rb

+20-6
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,33 @@ def register_additional_file_watchers(global_state:, outgoing_queue:)
223223
id: "workspace/didChangeWatchedFilesRails",
224224
method: "workspace/didChangeWatchedFiles",
225225
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
226-
watchers: [
227-
Interface::FileSystemWatcher.new(
228-
glob_pattern: "**/*structure.sql",
229-
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
230-
),
231-
],
226+
watchers: [structure_sql_file_watcher, fixture_file_watcher].compact,
232227
),
233228
),
234229
],
235230
),
236231
)
237232
end
238233

234+
sig { returns(Interface::FileSystemWatcher) }
235+
def structure_sql_file_watcher
236+
Interface::FileSystemWatcher.new(
237+
glob_pattern: "**/*structure.sql",
238+
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
239+
)
240+
end
241+
242+
sig { returns(T.nilable(Interface::FileSystemWatcher)) }
243+
def fixture_file_watcher
244+
paths = @rails_runner_client.fixture_paths
245+
return unless paths
246+
247+
Interface::FileSystemWatcher.new(
248+
glob_pattern: "{#{paths.join(",")}}/fixtures/**/*.{yml,yaml,yml.erb,yaml.erb}",
249+
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
250+
)
251+
end
252+
239253
sig { void }
240254
def offer_to_run_pending_migrations
241255
return unless @outgoing_queue

lib/ruby_lsp/ruby_lsp_rails/runner_client.rb

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class EmptyMessageError < MessageError; end
5151
sig { returns(String) }
5252
attr_reader :rails_root
5353

54+
sig { returns(T.nilable(T::Array[String])) }
55+
attr_reader :fixture_paths
56+
5457
sig { params(outgoing_queue: Thread::Queue).void }
5558
def initialize(outgoing_queue)
5659
@outgoing_queue = T.let(outgoing_queue, Thread::Queue)
@@ -89,6 +92,7 @@ def initialize(outgoing_queue)
8992

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

9498
unless ENV["RAILS_ENV"] == "test"

lib/ruby_lsp/ruby_lsp_rails/server.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
require "json"
55
require "open3"
6+
require "rails/test_help" # to determine the fixture_paths
67

78
module RubyLsp
89
module Rails
@@ -123,7 +124,11 @@ def initialize(stdout: $stdout, override_default_output_device: true)
123124
def start
124125
load_routes
125126
clear_file_system_resolver_hooks
126-
send_result({ message: "ok", root: ::Rails.root.to_s })
127+
send_result({
128+
message: "ok",
129+
root: ::Rails.root.to_s,
130+
fixture_paths: ActiveSupport::TestCase.fixture_paths,
131+
})
127132

128133
while @running
129134
headers = @stdin.gets("\r\n\r\n")

0 commit comments

Comments
 (0)