Skip to content

Commit

Permalink
Move supports_progress to global state (#2815)
Browse files Browse the repository at this point in the history
### Motivation

We want to allow add-ons to show progress bars if the editor supports it. However, whether it supports it or not is currently a state of `Store`, which add-ons don't have access to. We need to put that in the global state.

### Implementation

Moved `supports_progress` to the global state.

### Automated Tests

I got rid of a test that wasn't very useful and that was difficult to avoid flakiness after this change.
  • Loading branch information
vinistock authored Nov 1, 2024
1 parent fffed4d commit 93f9669
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
9 changes: 8 additions & 1 deletion lib/ruby_lsp/client_capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class ClientCapabilities
sig { returns(T::Boolean) }
attr_reader :supports_watching_files,
:supports_request_delegation,
:window_show_message_supports_extra_properties
:window_show_message_supports_extra_properties,
:supports_progress

sig { void }
def initialize
Expand All @@ -28,6 +29,9 @@ def initialize

# Which resource operations the editor supports, like renaming files
@supported_resource_operations = T.let([], T::Array[String])

# The editor supports displaying progress requests
@supports_progress = T.let(false, T::Boolean)
end

sig { params(capabilities: T::Hash[Symbol, T.untyped]).void }
Expand All @@ -50,6 +54,9 @@ def apply_client_capabilities(capabilities)
:additionalPropertiesSupport,
)
@window_show_message_supports_extra_properties = supports_additional_properties || false

progress = capabilities.dig(:window, :workDoneProgress)
@supports_progress = progress if progress
end

sig { returns(T::Boolean) }
Expand Down
8 changes: 3 additions & 5 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ def run_initialize(message)
client_name = options.dig(:clientInfo, :name)
@store.client_name = client_name if client_name

progress = options.dig(:capabilities, :window, :workDoneProgress)
@store.supports_progress = progress.nil? ? true : progress
configured_features = options.dig(:initializationOptions, :enabledFeatures)

configured_hints = options.dig(:initializationOptions, :featuresConfiguration, :inlayHint)
Expand Down Expand Up @@ -1105,7 +1103,7 @@ def perform_initial_indexing

sig { params(id: String, title: String, percentage: Integer).void }
def begin_progress(id, title, percentage: 0)
return unless @store.supports_progress
return unless @global_state.client_capabilities.supports_progress

send_message(Request.new(
id: @current_request_id,
Expand All @@ -1129,7 +1127,7 @@ def begin_progress(id, title, percentage: 0)

sig { params(id: String, percentage: Integer).void }
def progress(id, percentage)
return unless @store.supports_progress
return unless @global_state.client_capabilities.supports_progress

send_message(
Notification.new(
Expand All @@ -1148,7 +1146,7 @@ def progress(id, percentage)

sig { params(id: String).void }
def end_progress(id)
return unless @store.supports_progress
return unless @global_state.client_capabilities.supports_progress

send_message(
Notification.new(
Expand Down
4 changes: 0 additions & 4 deletions lib/ruby_lsp/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class Store

class NonExistingDocumentError < StandardError; end

sig { returns(T::Boolean) }
attr_accessor :supports_progress

sig { returns(T::Hash[Symbol, RequestConfig]) }
attr_accessor :features_configuration

Expand All @@ -19,7 +16,6 @@ class NonExistingDocumentError < StandardError; end
sig { void }
def initialize
@state = T.let({}, T::Hash[String, Document[T.untyped]])
@supports_progress = T.let(true, T::Boolean)
@features_configuration = T.let(
{
inlayHint: RequestConfig.new({
Expand Down
13 changes: 0 additions & 13 deletions test/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,6 @@ def test_server_info_includes_formatter
assert_equal("rubocop", hash.dig("formatter"))
end

def test_initialized_populates_index
capture_subprocess_io do
@server.process_message({ method: "initialized" })

assert_equal("$/progress", @server.pop_response.method)
assert_equal("$/progress", @server.pop_response.method)
assert_equal("$/progress", @server.pop_response.method)
assert_equal("$/progress", @server.pop_response.method)

refute_empty(@server.global_state.index)
end
end

def test_initialized_recovers_from_indexing_failures
@server.global_state.index.expects(:index_all).once.raises(StandardError, "boom!")
capture_subprocess_io do
Expand Down

0 comments on commit 93f9669

Please sign in to comment.