Skip to content

Commit

Permalink
Allow disabling pending migration prompt (#570)
Browse files Browse the repository at this point in the history
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
   }
 }
```
  • Loading branch information
vinistock authored Feb 3, 2025
1 parent 5c59f2f commit d44779e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def initialize
@rails_runner_client = T.let(NullClient.new, RunnerClient)
@global_state = T.let(nil, T.nilable(GlobalState))
@outgoing_queue = T.let(nil, T.nilable(Thread::Queue))
@settings = T.let(
{
enablePendingMigrationsPrompt: true,
},
T::Hash[Symbol, T.untyped],
)
@addon_mutex = T.let(Mutex.new, Mutex)
@client_mutex = T.let(Mutex.new, Mutex)
@client_mutex.lock
Expand All @@ -58,6 +64,9 @@ def activate(global_state, outgoing_queue)
@outgoing_queue = outgoing_queue
@outgoing_queue << Notification.window_log_message("Activating Ruby LSP Rails add-on v#{VERSION}")

addon_settings = @global_state.settings_for_addon(name)
@settings.merge!(addon_settings) if addon_settings

register_additional_file_watchers(global_state: global_state, outgoing_queue: outgoing_queue)

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

migration_message = @rails_runner_client.pending_migrations_message
return unless migration_message
Expand Down
29 changes: 29 additions & 0 deletions test/ruby_lsp_rails/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ class AddonTest < ActiveSupport::TestCase
ensure
T.must(outgoing_queue).close
end

test "migration dialog respects enabled setting" do
outgoing_queue = Thread::Queue.new
global_state = GlobalState.new
global_state.apply_options({
capabilities: { window: { showMessage: { messageActionItem: { additionalPropertiesSupport: true } } } },
initializationOptions: { addonSettings: { "Ruby LSP Rails": { enablePendingMigrationsPrompt: false } } },
})

refute(T.must(global_state.settings_for_addon("Ruby LSP Rails"))[:enablePendingMigrationsPrompt])

addon = Addon.new
addon.activate(global_state, outgoing_queue)

# Wait until activation is done
Thread.new do
addon.rails_runner_client
end.join

RunnerClient.any_instance.expects(:pending_migrations_message).never
addon.workspace_did_change_watched_files([
{
uri: "file://#{dummy_root}/db/migrate/20210901000000_create_foos.rb",
type: RubyLsp::Constant::FileChangeType::CREATED,
},
])
ensure
T.must(outgoing_queue).close
end
end
end
end

0 comments on commit d44779e

Please sign in to comment.