Skip to content

Allow disabling pending migration prompt #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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