Skip to content

Commit 7b4f4f6

Browse files
committed
Reload the runner if structure.sql changes
Closes #326
1 parent f768913 commit 7b4f4f6

File tree

5 files changed

+189
-93
lines changed

5 files changed

+189
-93
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ gem "sorbet-static-and-runtime", platforms: :ruby
1919
gem "tapioca", "~> 0.13", require: false, platforms: :ruby
2020
gem "psych", "~> 5.1", require: false
2121
gem "rails"
22+
gem "ruby-lsp", github: "Shopify/ruby-lsp"

Gemfile.lock

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@ GIT
66
rdoc (6.6.3.1)
77
psych (>= 4.0.0)
88

9+
GIT
10+
remote: https://github.com/Shopify/ruby-lsp.git
11+
revision: d07d9c14b71bf821a8533b7ee2312cb5e6d5b3c1
12+
specs:
13+
ruby-lsp (0.16.5)
14+
language_server-protocol (~> 3.17.0)
15+
prism (>= 0.23.0, < 0.25)
16+
sorbet-runtime (>= 0.5.10782)
17+
918
PATH
1019
remote: .
1120
specs:
1221
ruby-lsp-rails (0.3.5)
13-
ruby-lsp (>= 0.16.0, < 0.17.0)
22+
ruby-lsp (>= 0.16.5, < 0.17.0)
1423
sorbet-runtime (>= 0.5.9897)
1524

1625
GEM
@@ -223,10 +232,6 @@ GEM
223232
rubocop (~> 1.51)
224233
rubocop-sorbet (0.8.1)
225234
rubocop (>= 0.90.0)
226-
ruby-lsp (0.16.4)
227-
language_server-protocol (~> 3.17.0)
228-
prism (>= 0.22.0, < 0.25)
229-
sorbet-runtime (>= 0.5.10782)
230235
ruby-progressbar (1.13.0)
231236
ruby2_keywords (0.0.5)
232237
sorbet (0.5.11346)
@@ -286,6 +291,7 @@ DEPENDENCIES
286291
rubocop-rake (~> 0.6.0)
287292
rubocop-shopify (~> 2.15)
288293
rubocop-sorbet (~> 0.8)
294+
ruby-lsp!
289295
ruby-lsp-rails!
290296
sorbet-static-and-runtime
291297
sqlite3

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def activate(global_state, message_queue)
3131
$stderr.puts("Activating Ruby LSP Rails addon v#{VERSION}")
3232
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
3333
Thread.new { @client = RunnerClient.create_client }
34+
register_additional_file_watchers(global_state: global_state, message_queue: message_queue)
3435
end
3536

3637
sig { override.void }
@@ -95,6 +96,32 @@ def workspace_did_change_watched_files(changes)
9596
end
9697
end
9798

99+
sig { params(global_state: GlobalState, message_queue: Thread::Queue).void }
100+
def register_additional_file_watchers(global_state:, message_queue:)
101+
return unless global_state.supports_watching_files
102+
103+
message_queue << Request.new(
104+
id: "ruby-lsp-rails-file-watcher",
105+
method: "client/registerCapability",
106+
params: Interface::RegistrationParams.new(
107+
registrations: [
108+
Interface::Registration.new(
109+
id: "workspace/didChangeWatchedFilesRails",
110+
method: "workspace/didChangeWatchedFiles",
111+
register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
112+
watchers: [
113+
Interface::FileSystemWatcher.new(
114+
glob_pattern: "**/*structure.sql",
115+
kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
116+
),
117+
],
118+
),
119+
),
120+
],
121+
),
122+
)
123+
end
124+
98125
sig { override.returns(String) }
99126
def name
100127
"Ruby LSP Rails"

ruby-lsp-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
2323
Dir["lib/**/*", "LICENSE.txt", "Rakefile", "README.md"]
2424
end
2525

26-
spec.add_dependency("ruby-lsp", ">= 0.16.0", "< 0.17.0")
26+
spec.add_dependency("ruby-lsp", ">= 0.16.5", "< 0.17.0")
2727
spec.add_dependency("sorbet-runtime", ">= 0.5.9897")
2828
end

0 commit comments

Comments
 (0)