Skip to content

Commit d44779e

Browse files
authoredFeb 3, 2025
Allow disabling pending migration prompt (#570)
Closes #540 Allow disabling the pending migration prompt through an addon setting. To disable, users can add this to their configuration: ```json "rubyLsp.addonSettings": { "Ruby LSP Rails": { "enablePendingMigrationsPrompt": false } } ```
1 parent 5c59f2f commit d44779e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
 

‎lib/ruby_lsp/ruby_lsp_rails/addon.rb

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def initialize
3232
@rails_runner_client = T.let(NullClient.new, RunnerClient)
3333
@global_state = T.let(nil, T.nilable(GlobalState))
3434
@outgoing_queue = T.let(nil, T.nilable(Thread::Queue))
35+
@settings = T.let(
36+
{
37+
enablePendingMigrationsPrompt: true,
38+
},
39+
T::Hash[Symbol, T.untyped],
40+
)
3541
@addon_mutex = T.let(Mutex.new, Mutex)
3642
@client_mutex = T.let(Mutex.new, Mutex)
3743
@client_mutex.lock
@@ -58,6 +64,9 @@ def activate(global_state, outgoing_queue)
5864
@outgoing_queue = outgoing_queue
5965
@outgoing_queue << Notification.window_log_message("Activating Ruby LSP Rails add-on v#{VERSION}")
6066

67+
addon_settings = @global_state.settings_for_addon(name)
68+
@settings.merge!(addon_settings) if addon_settings
69+
6170
register_additional_file_watchers(global_state: global_state, outgoing_queue: outgoing_queue)
6271

6372
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
@@ -258,6 +267,7 @@ def fixture_file_watcher
258267
def offer_to_run_pending_migrations
259268
return unless @outgoing_queue
260269
return unless @global_state&.client_capabilities&.window_show_message_supports_extra_properties
270+
return unless @settings[:enablePendingMigrationsPrompt]
261271

262272
migration_message = @rails_runner_client.pending_migrations_message
263273
return unless migration_message

‎test/ruby_lsp_rails/addon_test.rb

+29
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,35 @@ class AddonTest < ActiveSupport::TestCase
9292
ensure
9393
T.must(outgoing_queue).close
9494
end
95+
96+
test "migration dialog respects enabled setting" do
97+
outgoing_queue = Thread::Queue.new
98+
global_state = GlobalState.new
99+
global_state.apply_options({
100+
capabilities: { window: { showMessage: { messageActionItem: { additionalPropertiesSupport: true } } } },
101+
initializationOptions: { addonSettings: { "Ruby LSP Rails": { enablePendingMigrationsPrompt: false } } },
102+
})
103+
104+
refute(T.must(global_state.settings_for_addon("Ruby LSP Rails"))[:enablePendingMigrationsPrompt])
105+
106+
addon = Addon.new
107+
addon.activate(global_state, outgoing_queue)
108+
109+
# Wait until activation is done
110+
Thread.new do
111+
addon.rails_runner_client
112+
end.join
113+
114+
RunnerClient.any_instance.expects(:pending_migrations_message).never
115+
addon.workspace_did_change_watched_files([
116+
{
117+
uri: "file://#{dummy_root}/db/migrate/20210901000000_create_foos.rb",
118+
type: RubyLsp::Constant::FileChangeType::CREATED,
119+
},
120+
])
121+
ensure
122+
T.must(outgoing_queue).close
123+
end
95124
end
96125
end
97126
end

0 commit comments

Comments
 (0)
Failed to load comments.