From 93f966998bb7df5e804b63b559d0592780c8697a Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 1 Nov 2024 10:29:54 -0400 Subject: [PATCH] Move `supports_progress` to global state (#2815) ### 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. --- lib/ruby_lsp/client_capabilities.rb | 9 ++++++++- lib/ruby_lsp/server.rb | 8 +++----- lib/ruby_lsp/store.rb | 4 ---- test/server_test.rb | 13 ------------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/lib/ruby_lsp/client_capabilities.rb b/lib/ruby_lsp/client_capabilities.rb index b30b5aa3e..adce616b1 100644 --- a/lib/ruby_lsp/client_capabilities.rb +++ b/lib/ruby_lsp/client_capabilities.rb @@ -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 @@ -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 } @@ -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) } diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index 0de646c81..7efdda294 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -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) @@ -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, @@ -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( @@ -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( diff --git a/lib/ruby_lsp/store.rb b/lib/ruby_lsp/store.rb index 4de87f2f1..2bcd3389b 100644 --- a/lib/ruby_lsp/store.rb +++ b/lib/ruby_lsp/store.rb @@ -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 @@ -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({ diff --git a/test/server_test.rb b/test/server_test.rb index d0ae7faed..321ea0d7f 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -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