From 6c1da444d68c5cf8e9d5e15e2b2f7661c078b6a2 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Thu, 11 Jan 2024 18:40:05 +0000 Subject: [PATCH] Rename Request#response to Request#perform (#1297) As @vinistock pointed out, using `#response` seems to imply that the request was already completed before it's called. In ruby-lsp's case, many requests are used in this pattern: ```rb FooRequest.new(args).response ``` In this context, it feels like the computation is done in `FooRequest#initialize` and `#response` is just a getter, which is a bit misleading. So this commit renames `#response` to `#perform` to make it more clear. --- lib/ruby_lsp/executor.rb | 44 +++++++++---------- lib/ruby_lsp/requests/code_action_resolve.rb | 2 +- lib/ruby_lsp/requests/code_actions.rb | 2 +- lib/ruby_lsp/requests/code_lens.rb | 2 +- lib/ruby_lsp/requests/completion.rb | 2 +- lib/ruby_lsp/requests/definition.rb | 2 +- lib/ruby_lsp/requests/diagnostics.rb | 2 +- lib/ruby_lsp/requests/document_highlight.rb | 2 +- lib/ruby_lsp/requests/document_link.rb | 2 +- lib/ruby_lsp/requests/document_symbol.rb | 2 +- lib/ruby_lsp/requests/folding_ranges.rb | 2 +- lib/ruby_lsp/requests/formatting.rb | 2 +- lib/ruby_lsp/requests/hover.rb | 2 +- lib/ruby_lsp/requests/inlay_hints.rb | 2 +- lib/ruby_lsp/requests/on_type_formatting.rb | 2 +- lib/ruby_lsp/requests/request.rb | 2 +- lib/ruby_lsp/requests/selection_ranges.rb | 2 +- .../requests/semantic_highlighting.rb | 2 +- lib/ruby_lsp/requests/show_syntax_tree.rb | 2 +- lib/ruby_lsp/requests/signature_help.rb | 2 +- lib/ruby_lsp/requests/workspace_symbol.rb | 2 +- test/expectations/expectations_test_runner.rb | 4 +- .../code_action_resolve_expectations_test.rb | 2 +- .../code_actions_expectations_test.rb | 2 +- test/requests/code_actions_formatting_test.rb | 4 +- test/requests/code_lens_expectations_test.rb | 12 ++--- .../requests/diagnostics_expectations_test.rb | 4 +- test/requests/diagnostics_test.rb | 8 ++-- .../document_highlight_expectations_test.rb | 2 +- .../document_link_expectations_test.rb | 2 +- .../folding_ranges_expectations_test.rb | 2 +- test/requests/formatting_expectations_test.rb | 2 +- test/requests/formatting_test.rb | 10 ++--- .../requests/inlay_hints_expectations_test.rb | 6 +-- test/requests/on_type_formatting_test.rb | 40 ++++++++--------- .../selection_ranges_expectations_test.rb | 2 +- ...semantic_highlighting_expectations_test.rb | 2 +- test/requests/workspace_symbol_test.rb | 26 +++++------ 38 files changed, 107 insertions(+), 107 deletions(-) diff --git a/lib/ruby_lsp/executor.rb b/lib/ruby_lsp/executor.rb index f82e580c2..77700efab 100644 --- a/lib/ruby_lsp/executor.rb +++ b/lib/ruby_lsp/executor.rb @@ -94,7 +94,7 @@ def run(request) cached_response = document.cache_get(request[:method]) return cached_response if cached_response - # Run listeners for the document + # Run requests for the document dispatcher = Prism::Dispatcher.new folding_range = Requests::FoldingRanges.new(document.parse_result.comments, dispatcher) document_symbol = Requests::DocumentSymbol.new(dispatcher) @@ -107,13 +107,13 @@ def run(request) # Store all responses retrieve in this round of visits in the cache and then return the response for the request # we actually received - document.cache_set("textDocument/foldingRange", folding_range.response) - document.cache_set("textDocument/documentSymbol", document_symbol.response) - document.cache_set("textDocument/documentLink", document_link.response) - document.cache_set("textDocument/codeLens", code_lens.response) + document.cache_set("textDocument/foldingRange", folding_range.perform) + document.cache_set("textDocument/documentSymbol", document_symbol.perform) + document.cache_set("textDocument/documentLink", document_link.perform) + document.cache_set("textDocument/codeLens", code_lens.perform) document.cache_set( "textDocument/semanticTokens/full", - Requests::Support::SemanticTokenEncoder.new.encode(semantic_highlighting.response), + Requests::Support::SemanticTokenEncoder.new.encode(semantic_highlighting.perform), ) document.cache_get(request[:method]) when "textDocument/semanticTokens/range" @@ -147,7 +147,7 @@ def run(request) document = @store.get(uri) request = Requests::DocumentHighlight.new(document, request.dig(:params, :position), dispatcher) dispatcher.dispatch(document.tree) - request.response + request.perform when "textDocument/onTypeFormatting" on_type_formatting(uri, request.dig(:params, :position), request.dig(:params, :ch)) when "textDocument/hover" @@ -159,14 +159,14 @@ def run(request) request.dig(:params, :position), dispatcher, document.typechecker_enabled?, - ).response + ).perform when "textDocument/inlayHint" hints_configurations = T.must(@store.features_configuration.dig(:inlayHint)) dispatcher = Prism::Dispatcher.new document = @store.get(uri) request = Requests::InlayHints.new(document, request.dig(:params, :range), hints_configurations, dispatcher) dispatcher.visit(document.tree) - request.response + request.perform when "textDocument/codeAction" code_action(uri, request.dig(:params, :range), request.dig(:params, :context)) when "codeAction/resolve" @@ -194,7 +194,7 @@ def run(request) request.dig(:params, :position), document.typechecker_enabled?, dispatcher, - ).response + ).perform when "textDocument/signatureHelp" dispatcher = Prism::Dispatcher.new document = @store.get(uri) @@ -205,7 +205,7 @@ def run(request) request.dig(:params, :position), request.dig(:params, :context), dispatcher, - ).response + ).perform when "textDocument/definition" dispatcher = Prism::Dispatcher.new document = @store.get(uri) @@ -215,7 +215,7 @@ def run(request) request.dig(:params, :position), dispatcher, document.typechecker_enabled?, - ).response + ).perform when "workspace/didChangeWatchedFiles" did_change_watched_files(request.dig(:params, :changes)) when "workspace/symbol" @@ -287,12 +287,12 @@ def perform_initial_indexing sig { params(query: T.nilable(String)).returns(T::Array[Interface::WorkspaceSymbol]) } def workspace_symbol(query) - Requests::WorkspaceSymbol.new(query, @index).response + Requests::WorkspaceSymbol.new(query, @index).perform end sig { params(uri: URI::Generic, range: T.nilable(T::Hash[Symbol, T.untyped])).returns({ ast: String }) } def show_syntax_tree(uri, range) - { ast: Requests::ShowSyntaxTree.new(@store.get(uri), range).response } + { ast: Requests::ShowSyntaxTree.new(@store.get(uri), range).perform } end sig do @@ -323,7 +323,7 @@ def text_document_did_close(uri) end def selection_range(uri, positions) ranges = @store.cache_fetch(uri, "textDocument/selectionRange") do |document| - Requests::SelectionRanges.new(document).response + Requests::SelectionRanges.new(document).perform end # Per the selection range request spec (https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange), @@ -350,7 +350,7 @@ def formatting(uri) path = uri.to_standardized_path return unless path.nil? || path.start_with?(T.must(@store.workspace_uri.to_standardized_path)) - Requests::Formatting.new(@store.get(uri), formatter: @store.formatter).response + Requests::Formatting.new(@store.get(uri), formatter: @store.formatter).perform end sig do @@ -361,7 +361,7 @@ def formatting(uri) ).returns(T::Array[Interface::TextEdit]) end def on_type_formatting(uri, position, character) - Requests::OnTypeFormatting.new(@store.get(uri), position, character).response + Requests::OnTypeFormatting.new(@store.get(uri), position, character).perform end sig do @@ -374,14 +374,14 @@ def on_type_formatting(uri, position, character) def code_action(uri, range, context) document = @store.get(uri) - Requests::CodeActions.new(document, range, context).response + Requests::CodeActions.new(document, range, context).perform end sig { params(params: T::Hash[Symbol, T.untyped]).returns(Interface::CodeAction) } def code_action_resolve(params) uri = URI(params.dig(:data, :uri)) document = @store.get(uri) - result = Requests::CodeActionResolve.new(document, params).response + result = Requests::CodeActionResolve.new(document, params).perform case result when Requests::CodeActionResolve::Error::EmptySelection @@ -415,7 +415,7 @@ def diagnostic(uri) return unless path.nil? || path.start_with?(T.must(@store.workspace_uri.to_standardized_path)) response = @store.cache_fetch(uri, "textDocument/diagnostic") do |document| - Requests::Diagnostics.new(document).response + Requests::Diagnostics.new(document).perform end Interface::FullDocumentDiagnosticReport.new(kind: "full", items: response) if response @@ -428,10 +428,10 @@ def semantic_tokens_range(uri, range) end_line = range.dig(:end, :line) dispatcher = Prism::Dispatcher.new - listener = Requests::SemanticHighlighting.new(dispatcher, range: start_line..end_line) + request = Requests::SemanticHighlighting.new(dispatcher, range: start_line..end_line) dispatcher.visit(document.tree) - Requests::Support::SemanticTokenEncoder.new.encode(listener.response) + Requests::Support::SemanticTokenEncoder.new.encode(request.perform) end sig { params(id: String, title: String, percentage: Integer).void } diff --git a/lib/ruby_lsp/requests/code_action_resolve.rb b/lib/ruby_lsp/requests/code_action_resolve.rb index 953858e39..5d6c9b310 100644 --- a/lib/ruby_lsp/requests/code_action_resolve.rb +++ b/lib/ruby_lsp/requests/code_action_resolve.rb @@ -42,7 +42,7 @@ def initialize(document, code_action) end sig { override.returns(T.any(Interface::CodeAction, Error)) } - def response + def perform return Error::EmptySelection if @document.source.empty? source_range = @code_action.dig(:data, :range) diff --git a/lib/ruby_lsp/requests/code_actions.rb b/lib/ruby_lsp/requests/code_actions.rb index ac358ebc0..7ee995dfb 100644 --- a/lib/ruby_lsp/requests/code_actions.rb +++ b/lib/ruby_lsp/requests/code_actions.rb @@ -44,7 +44,7 @@ def initialize(document, range, context) end sig { override.returns(T.nilable(T.all(T::Array[Interface::CodeAction], Object))) } - def response + def perform diagnostics = @context[:diagnostics] code_actions = diagnostics.flat_map do |diagnostic| diff --git a/lib/ruby_lsp/requests/code_lens.rb b/lib/ruby_lsp/requests/code_lens.rb index 82424377d..c09dda4a4 100644 --- a/lib/ruby_lsp/requests/code_lens.rb +++ b/lib/ruby_lsp/requests/code_lens.rb @@ -60,7 +60,7 @@ def initialize(uri, lenses_configuration, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listeners.flat_map(&:response) end end diff --git a/lib/ruby_lsp/requests/completion.rb b/lib/ruby_lsp/requests/completion.rb index c2599b09c..99f5dc13f 100644 --- a/lib/ruby_lsp/requests/completion.rb +++ b/lib/ruby_lsp/requests/completion.rb @@ -100,7 +100,7 @@ def initialize(document, index, position, typechecker_enabled, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform return [] unless @target @dispatcher.dispatch_once(@target) diff --git a/lib/ruby_lsp/requests/definition.rb b/lib/ruby_lsp/requests/definition.rb index dd9c11db2..9f4088f08 100644 --- a/lib/ruby_lsp/requests/definition.rb +++ b/lib/ruby_lsp/requests/definition.rb @@ -62,7 +62,7 @@ def initialize(document, index, position, dispatcher, typechecker_enabled) end sig { override.returns(ResponseType) } - def response + def perform @dispatcher.dispatch_once(@target) result = [] diff --git a/lib/ruby_lsp/requests/diagnostics.rb b/lib/ruby_lsp/requests/diagnostics.rb index 4558ffb2f..856fd6212 100644 --- a/lib/ruby_lsp/requests/diagnostics.rb +++ b/lib/ruby_lsp/requests/diagnostics.rb @@ -41,7 +41,7 @@ def initialize(document) end sig { override.returns(T.nilable(T.all(T::Array[Interface::Diagnostic], Object))) } - def response + def perform # Running RuboCop is slow, so to avoid excessive runs we only do so if the file is syntactically valid return syntax_error_diagnostics if @document.syntax_error? return [] unless defined?(Support::RuboCopDiagnosticsRunner) diff --git a/lib/ruby_lsp/requests/document_highlight.rb b/lib/ruby_lsp/requests/document_highlight.rb index 3c179987b..27a7b1588 100644 --- a/lib/ruby_lsp/requests/document_highlight.rb +++ b/lib/ruby_lsp/requests/document_highlight.rb @@ -43,7 +43,7 @@ def initialize(document, position, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listener.response end end diff --git a/lib/ruby_lsp/requests/document_link.rb b/lib/ruby_lsp/requests/document_link.rb index 39d0bd2fe..a061a8e48 100644 --- a/lib/ruby_lsp/requests/document_link.rb +++ b/lib/ruby_lsp/requests/document_link.rb @@ -46,7 +46,7 @@ def initialize(uri, comments, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listener.response end end diff --git a/lib/ruby_lsp/requests/document_symbol.rb b/lib/ruby_lsp/requests/document_symbol.rb index 883b41b06..75090e462 100644 --- a/lib/ruby_lsp/requests/document_symbol.rb +++ b/lib/ruby_lsp/requests/document_symbol.rb @@ -63,7 +63,7 @@ def initialize(dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listeners.flat_map(&:response).compact end end diff --git a/lib/ruby_lsp/requests/folding_ranges.rb b/lib/ruby_lsp/requests/folding_ranges.rb index 0b2af34c1..8beed4c61 100644 --- a/lib/ruby_lsp/requests/folding_ranges.rb +++ b/lib/ruby_lsp/requests/folding_ranges.rb @@ -39,7 +39,7 @@ def initialize(comments, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listener.response end end diff --git a/lib/ruby_lsp/requests/formatting.rb b/lib/ruby_lsp/requests/formatting.rb index fb8fd1e25..149c331eb 100644 --- a/lib/ruby_lsp/requests/formatting.rb +++ b/lib/ruby_lsp/requests/formatting.rb @@ -62,7 +62,7 @@ def initialize(document, formatter: "auto") end sig { override.returns(T.nilable(T.all(T::Array[Interface::TextEdit], Object))) } - def response + def perform return if @formatter == "none" return if @document.syntax_error? diff --git a/lib/ruby_lsp/requests/hover.rb b/lib/ruby_lsp/requests/hover.rb index 67e0aa7d7..7a3fd6327 100644 --- a/lib/ruby_lsp/requests/hover.rb +++ b/lib/ruby_lsp/requests/hover.rb @@ -72,7 +72,7 @@ def initialize(document, index, position, dispatcher, typechecker_enabled) end sig { override.returns(ResponseType) } - def response + def perform @dispatcher.dispatch_once(@target) responses = @listeners.map(&:response).compact diff --git a/lib/ruby_lsp/requests/inlay_hints.rb b/lib/ruby_lsp/requests/inlay_hints.rb index 90f8ede57..00f59ab4a 100644 --- a/lib/ruby_lsp/requests/inlay_hints.rb +++ b/lib/ruby_lsp/requests/inlay_hints.rb @@ -72,7 +72,7 @@ def initialize(document, range, hints_configuration, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform @listener.response end end diff --git a/lib/ruby_lsp/requests/on_type_formatting.rb b/lib/ruby_lsp/requests/on_type_formatting.rb index 7bd82ea13..7fa67fd16 100644 --- a/lib/ruby_lsp/requests/on_type_formatting.rb +++ b/lib/ruby_lsp/requests/on_type_formatting.rb @@ -53,7 +53,7 @@ def initialize(document, position, trigger_character) end sig { override.returns(T.all(T::Array[Interface::TextEdit], Object)) } - def response + def perform case @trigger_character when "{" handle_curly_brace if @document.syntax_error? diff --git a/lib/ruby_lsp/requests/request.rb b/lib/ruby_lsp/requests/request.rb index 6b3ae4434..a140af4d7 100644 --- a/lib/ruby_lsp/requests/request.rb +++ b/lib/ruby_lsp/requests/request.rb @@ -11,7 +11,7 @@ class Request abstract! sig { abstract.returns(T.anything) } - def response; end + def perform; end end end end diff --git a/lib/ruby_lsp/requests/selection_ranges.rb b/lib/ruby_lsp/requests/selection_ranges.rb index bffe49824..f08f3face 100644 --- a/lib/ruby_lsp/requests/selection_ranges.rb +++ b/lib/ruby_lsp/requests/selection_ranges.rb @@ -32,7 +32,7 @@ def initialize(document) end sig { override.returns(T.all(T::Array[Support::SelectionRange], Object)) } - def response + def perform # [node, parent] queue = [[@document.tree, nil]] diff --git a/lib/ruby_lsp/requests/semantic_highlighting.rb b/lib/ruby_lsp/requests/semantic_highlighting.rb index 901a0f87b..5f98f4bfa 100644 --- a/lib/ruby_lsp/requests/semantic_highlighting.rb +++ b/lib/ruby_lsp/requests/semantic_highlighting.rb @@ -50,7 +50,7 @@ def initialize(dispatcher, range: nil) end sig { override.returns(ResponseType) } - def response + def perform @listener.response end end diff --git a/lib/ruby_lsp/requests/show_syntax_tree.rb b/lib/ruby_lsp/requests/show_syntax_tree.rb index 0a6bc6739..1d7dbd1ea 100644 --- a/lib/ruby_lsp/requests/show_syntax_tree.rb +++ b/lib/ruby_lsp/requests/show_syntax_tree.rb @@ -28,7 +28,7 @@ def initialize(document, range) end sig { override.returns(String) } - def response + def perform return ast_for_range if @range output_string = +"" diff --git a/lib/ruby_lsp/requests/signature_help.rb b/lib/ruby_lsp/requests/signature_help.rb index da107d6bc..e50369852 100644 --- a/lib/ruby_lsp/requests/signature_help.rb +++ b/lib/ruby_lsp/requests/signature_help.rb @@ -76,7 +76,7 @@ def initialize(document, index, position, context, dispatcher) end sig { override.returns(ResponseType) } - def response + def perform return unless @target @dispatcher.dispatch_once(@target) diff --git a/lib/ruby_lsp/requests/workspace_symbol.rb b/lib/ruby_lsp/requests/workspace_symbol.rb index b30fe12b7..da024785f 100644 --- a/lib/ruby_lsp/requests/workspace_symbol.rb +++ b/lib/ruby_lsp/requests/workspace_symbol.rb @@ -30,7 +30,7 @@ def initialize(query, index) end sig { override.returns(T::Array[Interface::WorkspaceSymbol]) } - def response + def perform @index.fuzzy_search(@query).filter_map do |entry| # If the project is using Sorbet, we let Sorbet handle symbols defined inside the project itself and RBIs, but # we still return entries defined in gems to allow developers to jump directly to the source diff --git a/test/expectations/expectations_test_runner.rb b/test/expectations/expectations_test_runner.rb index e7299443b..8343de9d1 100644 --- a/test/expectations/expectations_test_runner.rb +++ b/test/expectations/expectations_test_runner.rb @@ -15,9 +15,9 @@ def run_expectations(source) params = @__params&.any? ? @__params : default_args document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: URI("file:///fake.rb")) dispatcher = Prism::Dispatcher.new - listener = #{handler_class}.new(dispatcher) + request = #{handler_class}.new(dispatcher) dispatcher.dispatch(document.tree) - listener.response + request.perform end def assert_expectations(source, expected) diff --git a/test/requests/code_action_resolve_expectations_test.rb b/test/requests/code_action_resolve_expectations_test.rb index b5b91acff..68accad13 100644 --- a/test/requests/code_action_resolve_expectations_test.rb +++ b/test/requests/code_action_resolve_expectations_test.rb @@ -11,7 +11,7 @@ def run_expectations(source) params = @__params&.any? ? @__params : default_args document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: URI("file:///fake.rb")) - RubyLsp::Requests::CodeActionResolve.new(document, params).response + RubyLsp::Requests::CodeActionResolve.new(document, params).perform end def assert_expectations(source, expected) diff --git a/test/requests/code_actions_expectations_test.rb b/test/requests/code_actions_expectations_test.rb index 4efe06e3a..5600e7072 100644 --- a/test/requests/code_actions_expectations_test.rb +++ b/test/requests/code_actions_expectations_test.rb @@ -17,7 +17,7 @@ def run_expectations(source) document, params[:range], params[:context], - ).response + ).perform end assert_empty(stdout) diff --git a/test/requests/code_actions_formatting_test.rb b/test/requests/code_actions_formatting_test.rb index ac009c557..639a17c1c 100644 --- a/test/requests/code_actions_formatting_test.rb +++ b/test/requests/code_actions_formatting_test.rb @@ -75,12 +75,12 @@ def assert_corrects_to_expected(diagnostic_code, code_action_title, source, expe encoding: LanguageServer::Protocol::Constant::PositionEncodingKind::UTF16, ) - diagnostics = RubyLsp::Requests::Diagnostics.new(document).response + diagnostics = RubyLsp::Requests::Diagnostics.new(document).perform diagnostic = T.must(T.must(diagnostics).find { |d| d.code == diagnostic_code }) range = diagnostic.range.to_hash.transform_values(&:to_hash) result = RubyLsp::Requests::CodeActions.new(document, range, { diagnostics: [JSON.parse(T.must(diagnostic).to_json, symbolize_names: true)], - }).response + }).perform # CodeActions#run returns Array. We're interested in the # hashes here, so cast to untyped and only look at those. diff --git a/test/requests/code_lens_expectations_test.rb b/test/requests/code_lens_expectations_test.rb index d37dbabc7..dd6149337 100644 --- a/test/requests/code_lens_expectations_test.rb +++ b/test/requests/code_lens_expectations_test.rb @@ -15,7 +15,7 @@ def run_expectations(source) stub_test_library("minitest") listener = RubyLsp::Requests::CodeLens.new(uri, default_lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - listener.response + listener.perform end def test_command_generation_for_test_unit @@ -32,7 +32,7 @@ def test_bar; end dispatcher = Prism::Dispatcher.new listener = RubyLsp::Requests::CodeLens.new(uri, default_lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - response = listener.response + response = listener.perform assert_equal(6, response.size) @@ -59,7 +59,7 @@ def test_bar; end stub_test_library("unknown") listener = RubyLsp::Requests::CodeLens.new(uri, default_lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - response = listener.response + response = listener.perform assert_empty(response) end @@ -78,7 +78,7 @@ def test_bar; end stub_test_library("rspec") listener = RubyLsp::Requests::CodeLens.new(uri, default_lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - response = listener.response + response = listener.perform assert_empty(response) end @@ -97,7 +97,7 @@ def test_bar; end stub_test_library("minitest") listener = RubyLsp::Requests::CodeLens.new(uri, default_lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - response = listener.response + response = listener.perform assert_empty(response) end @@ -112,7 +112,7 @@ def test_skip_gemfile_links lenses_configuration = RubyLsp::RequestConfig.new({ gemfileLinks: false }) listener = RubyLsp::Requests::CodeLens.new(uri, lenses_configuration, dispatcher) dispatcher.dispatch(document.tree) - response = listener.response + response = listener.perform assert_empty(response) end diff --git a/test/requests/diagnostics_expectations_test.rb b/test/requests/diagnostics_expectations_test.rb index fb48f0543..4a6b47d12 100644 --- a/test/requests/diagnostics_expectations_test.rb +++ b/test/requests/diagnostics_expectations_test.rb @@ -9,12 +9,12 @@ class DiagnosticsExpectationsTest < ExpectationsTestRunner def run_expectations(source) document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: URI::Generic.from_path(path: __FILE__)) - RubyLsp::Requests::Diagnostics.new(document).response + RubyLsp::Requests::Diagnostics.new(document).perform result = T.let(nil, T.nilable(T::Array[RubyLsp::Interface::Diagnostic])) stdout, _ = capture_io do result = T.cast( - RubyLsp::Requests::Diagnostics.new(document).response, + RubyLsp::Requests::Diagnostics.new(document).perform, T::Array[RubyLsp::Interface::Diagnostic], ) end diff --git a/test/requests/diagnostics_test.rb b/test/requests/diagnostics_test.rb index 3be9703d4..48b0b4aca 100644 --- a/test/requests/diagnostics_test.rb +++ b/test/requests/diagnostics_test.rb @@ -12,7 +12,7 @@ def test_empty_diagnostics_for_ignored_file uri: URI::Generic.from_path(path: fixture_path), ) - result = RubyLsp::Requests::Diagnostics.new(document).response + result = RubyLsp::Requests::Diagnostics.new(document).perform assert_empty(result) end @@ -21,7 +21,7 @@ def test_returns_syntax_error_diagnostics def foo RUBY - diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).response) + diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).perform) assert_equal(2, diagnostics.length) assert_equal("expected an `end` to close the `def` statement", T.must(diagnostics.last).message) @@ -39,7 +39,7 @@ def foo klass = RubyLsp::Requests::Support::RuboCopDiagnosticsRunner RubyLsp::Requests::Support.send(:remove_const, :RuboCopDiagnosticsRunner) - diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).response) + diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).perform) assert_empty(diagnostics) ensure @@ -54,7 +54,7 @@ def foo end RUBY - diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).response) + diagnostics = T.must(RubyLsp::Requests::Diagnostics.new(document).perform) refute_empty(diagnostics) end diff --git a/test/requests/document_highlight_expectations_test.rb b/test/requests/document_highlight_expectations_test.rb index abf8f927c..f383beab8 100644 --- a/test/requests/document_highlight_expectations_test.rb +++ b/test/requests/document_highlight_expectations_test.rb @@ -15,7 +15,7 @@ def run_expectations(source) dispatcher = Prism::Dispatcher.new listener = RubyLsp::Requests::DocumentHighlight.new(document, params.first, dispatcher) dispatcher.dispatch(document.tree) - listener.response + listener.perform end def default_args diff --git a/test/requests/document_link_expectations_test.rb b/test/requests/document_link_expectations_test.rb index d7beba2be..299502e8d 100644 --- a/test/requests/document_link_expectations_test.rb +++ b/test/requests/document_link_expectations_test.rb @@ -27,7 +27,7 @@ def run_expectations(source) dispatcher = Prism::Dispatcher.new listener = RubyLsp::Requests::DocumentLink.new(uri, document.comments, dispatcher) dispatcher.dispatch(document.tree) - listener.response + listener.perform end private diff --git a/test/requests/folding_ranges_expectations_test.rb b/test/requests/folding_ranges_expectations_test.rb index d50437cd9..66dbfdb31 100644 --- a/test/requests/folding_ranges_expectations_test.rb +++ b/test/requests/folding_ranges_expectations_test.rb @@ -14,6 +14,6 @@ def run_expectations(source) dispatcher = Prism::Dispatcher.new listener = RubyLsp::Requests::FoldingRanges.new(document.parse_result.comments, dispatcher) dispatcher.dispatch(document.tree) - listener.response + listener.perform end end diff --git a/test/requests/formatting_expectations_test.rb b/test/requests/formatting_expectations_test.rb index cf67e9956..dc28eae45 100644 --- a/test/requests/formatting_expectations_test.rb +++ b/test/requests/formatting_expectations_test.rb @@ -9,7 +9,7 @@ class FormattingExpectationsTest < ExpectationsTestRunner def run_expectations(source) document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: URI::Generic.from_path(path: __FILE__)) - RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").response&.first&.new_text + RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").perform&.first&.new_text end def assert_expectations(source, expected) diff --git a/test/requests/formatting_test.rb b/test/requests/formatting_test.rb index 67a391a82..82aa2f2ef 100644 --- a/test/requests/formatting_test.rb +++ b/test/requests/formatting_test.rb @@ -36,7 +36,7 @@ def foo def test_does_not_format_with_formatter_is_none document = RubyLsp::RubyDocument.new(source: "def foo", version: 1, uri: URI::Generic.from_path(path: __FILE__)) - assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "none").response) + assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "none").perform) end def test_syntax_tree_formatting_uses_options_from_streerc @@ -72,7 +72,7 @@ def foo def test_syntax_tree_formatting_ignores_syntax_invalid_documents require "ruby_lsp/requests" document = RubyLsp::RubyDocument.new(source: "def foo", version: 1, uri: URI::Generic.from_path(path: __FILE__)) - assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "syntax_tree").response) + assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "syntax_tree").perform) end def test_syntax_tree_formatting_returns_nil_if_file_matches_ignore_files_options_from_streerc @@ -93,7 +93,7 @@ def foo def test_rubocop_formatting_ignores_syntax_invalid_documents document = RubyLsp::RubyDocument.new(source: "def foo", version: 1, uri: URI::Generic.from_path(path: __FILE__)) - assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").response) + assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").perform) end def test_returns_nil_if_document_is_already_formatted @@ -106,7 +106,7 @@ def foo end end RUBY - assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").response) + assert_nil(RubyLsp::Requests::Formatting.new(document, formatter: "rubocop").perform) end def test_allows_specifying_formatter @@ -150,7 +150,7 @@ def test_returns_nil_when_formatter_is_none def formatted_document(formatter) require "ruby_lsp/requests" - RubyLsp::Requests::Formatting.new(@document, formatter: formatter).response&.first&.new_text + RubyLsp::Requests::Formatting.new(@document, formatter: formatter).perform&.first&.new_text end def with_syntax_tree_config_file(contents) diff --git a/test/requests/inlay_hints_expectations_test.rb b/test/requests/inlay_hints_expectations_test.rb index f623514a1..e410c3bea 100644 --- a/test/requests/inlay_hints_expectations_test.rb +++ b/test/requests/inlay_hints_expectations_test.rb @@ -16,7 +16,7 @@ def run_expectations(source) hints_configuration = RubyLsp::RequestConfig.new({ implicitRescue: true, implicitHashValue: true }) request = RubyLsp::Requests::InlayHints.new(document, params.first, hints_configuration, dispatcher) dispatcher.dispatch(document.tree) - request.response + request.perform end def default_args @@ -33,7 +33,7 @@ def test_skip_implicit_hash_value hints_configuration = RubyLsp::RequestConfig.new({ implicitRescue: true, implicitHashValue: false }) request = RubyLsp::Requests::InlayHints.new(document, default_args.first, hints_configuration, dispatcher) dispatcher.dispatch(document.tree) - request.response + request.perform end def test_skip_implicit_rescue @@ -48,6 +48,6 @@ def test_skip_implicit_rescue hints_configuration = RubyLsp::RequestConfig.new({ implicitRescue: false, implicitHashValue: true }) request = RubyLsp::Requests::InlayHints.new(document, default_args.first, hints_configuration, dispatcher) dispatcher.dispatch(document.tree) - assert_empty(request.response) + assert_empty(request.perform) end end diff --git a/test/requests/on_type_formatting_test.rb b/test/requests/on_type_formatting_test.rb index 3c30ffbb8..5cb39dda4 100644 --- a/test/requests/on_type_formatting_test.rb +++ b/test/requests/on_type_formatting_test.rb @@ -16,7 +16,7 @@ def test_adding_missing_ends ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } }, @@ -46,7 +46,7 @@ def test_adding_missing_curly_brace_in_string_interpolation ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 11 }, "{").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 11 }, "{").perform expected_edits = [ { range: { start: { line: 0, character: 11 }, end: { line: 0, character: 11 } }, @@ -72,7 +72,7 @@ def test_adding_missing_pipe ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 12 }, "|").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 12 }, "|").perform expected_edits = [ { range: { start: { line: 0, character: 12 }, end: { line: 0, character: 12 } }, @@ -98,7 +98,7 @@ def test_pipe_is_not_added_in_regular_or_pipe ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 2 }, "|").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 2 }, "|").perform assert_empty(T.must(edits)) end @@ -121,7 +121,7 @@ def test_pipe_is_removed_if_user_adds_manually_after_completion }], version: 3, ) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 12 }, "|").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 12 }, "|").perform expected_edits = [ { range: { start: { line: 0, character: 12 }, end: { line: 0, character: 12 } }, @@ -144,7 +144,7 @@ def test_pipe_is_removed_if_user_adds_manually_after_completion version: 3, ) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 13 }, "|").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 13 }, "|").perform expected_edits = [ { range: { start: { line: 0, character: 13 }, end: { line: 0, character: 14 } }, @@ -177,7 +177,7 @@ def test_pipe_is_removed_if_user_adds_manually_after_block_argument }], version: 3, ) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 17 }, "|").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 17 }, "|").perform expected_edits = [ { range: { start: { line: 0, character: 17 }, end: { line: 0, character: 18 } }, @@ -203,7 +203,7 @@ def test_comment_continuation ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 14 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 14 }, "\n").perform expected_edits = [ { range: { start: { line: 0, character: 14 }, end: { line: 0, character: 14 } }, @@ -225,7 +225,7 @@ def test_keyword_handling ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 5 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 5 }, "\n").perform assert_empty(edits) end @@ -243,7 +243,7 @@ def test_comment_continuation_with_other_line_break_matches ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 14 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 14 }, "\n").perform expected_edits = [ { range: { start: { line: 0, character: 14 }, end: { line: 0, character: 14 } }, @@ -268,7 +268,7 @@ def test_comment_continuation_when_inserting_new_line_in_the_middle ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 7 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 7 }, "\n").perform expected_edits = [ { range: { start: { line: 0, character: 7 }, end: { line: 0, character: 7 } }, @@ -290,7 +290,7 @@ def test_breaking_line_between_keyword_and_more_content ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } }, @@ -321,7 +321,7 @@ def test_breaking_line_between_keyword_when_there_is_content_on_the_next_line ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 0, character: 2 }, "\n").perform assert_empty(edits) end @@ -337,7 +337,7 @@ def test_breaking_line_immediately_after_keyword ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform expected_edits = [ { range: { start: { line: 2, character: 2 }, end: { line: 2, character: 2 } }, @@ -354,7 +354,7 @@ def test_breaking_line_immediately_after_keyword def test_auto_indent_after_end_keyword document = RubyLsp::RubyDocument.new(source: +"if foo\nbar\nend", version: 1, uri: URI("file:///fake.rb")) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 2, character: 2 }, "d").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 2, character: 2 }, "d").perform expected_edits = [ { @@ -372,13 +372,13 @@ def test_auto_indent_after_end_keyword def test_breaking_line_if_a_keyword_is_part_of_method_call document = RubyLsp::RubyDocument.new(source: +" force({", version: 1, uri: URI("file:///fake.rb")) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform assert_empty(edits) end def test_breaking_line_if_a_keyword_in_a_subexpression document = RubyLsp::RubyDocument.new(source: +" var = (if", version: 1, uri: URI("file:///fake.rb")) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } }, @@ -408,7 +408,7 @@ def test_adding_heredoc_delimiter ) document.parse - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 2 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 2 }, end: { line: 1, character: 2 } }, @@ -429,7 +429,7 @@ def test_adding_heredoc_delimiter def test_completing_end_token_inside_parameters document = RubyLsp::RubyDocument.new(source: +"foo(proc do\n)", version: 1, uri: URI("file:///fake.rb")) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 0 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 0 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } }, @@ -450,7 +450,7 @@ def test_completing_end_token_inside_parameters def test_completing_end_token_inside_brackets document = RubyLsp::RubyDocument.new(source: +"foo[proc do\n]", version: 1, uri: URI("file:///fake.rb")) - edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 0 }, "\n").response + edits = RubyLsp::Requests::OnTypeFormatting.new(document, { line: 1, character: 0 }, "\n").perform expected_edits = [ { range: { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } }, diff --git a/test/requests/selection_ranges_expectations_test.rb b/test/requests/selection_ranges_expectations_test.rb index c1af505ac..8ead2d3df 100644 --- a/test/requests/selection_ranges_expectations_test.rb +++ b/test/requests/selection_ranges_expectations_test.rb @@ -9,7 +9,7 @@ class SelectionRangesExpectationsTest < ExpectationsTestRunner def run_expectations(source) document = RubyLsp::RubyDocument.new(source: source, version: 1, uri: URI("file:///fake.rb")) - actual = RubyLsp::Requests::SelectionRanges.new(document).response + actual = RubyLsp::Requests::SelectionRanges.new(document).perform params = @__params&.any? ? @__params : default_args filtered = params.map { |position| actual.find { |range| range.cover?(position) } } diff --git a/test/requests/semantic_highlighting_expectations_test.rb b/test/requests/semantic_highlighting_expectations_test.rb index 34edd066d..b37cb7bbf 100644 --- a/test/requests/semantic_highlighting_expectations_test.rb +++ b/test/requests/semantic_highlighting_expectations_test.rb @@ -21,7 +21,7 @@ def run_expectations(source) listener = RubyLsp::Requests::SemanticHighlighting.new(dispatcher, range: processed_range) dispatcher.dispatch(document.tree) - RubyLsp::Requests::Support::SemanticTokenEncoder.new.encode(listener.response) + RubyLsp::Requests::Support::SemanticTokenEncoder.new.encode(listener.perform) end def assert_expectations(source, expected) diff --git a/test/requests/workspace_symbol_test.rb b/test/requests/workspace_symbol_test.rb index 31988c0bc..d9ecfd643 100644 --- a/test/requests/workspace_symbol_test.rb +++ b/test/requests/workspace_symbol_test.rb @@ -17,15 +17,15 @@ module Bar; end CONSTANT = 1 RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("Foo", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("Foo", @index).perform.first assert_equal("Foo", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("Bar", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("Bar", @index).perform.first assert_equal("Bar", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::NAMESPACE, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("CONST", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("CONST", @index).perform.first assert_equal("CONSTANT", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CONSTANT, T.must(result).kind) end @@ -38,15 +38,15 @@ module Bar; end CONSTANT = 1 RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("Floo", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("Floo", @index).perform.first assert_equal("Foo", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("Bear", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("Bear", @index).perform.first assert_equal("Bar", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::NAMESPACE, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("CONF", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("CONF", @index).perform.first assert_equal("CONSTANT", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CONSTANT, T.must(result).kind) end @@ -65,7 +65,7 @@ class Foo; end class Foo; end RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("Foo", @index).response + result = RubyLsp::Requests::WorkspaceSymbol.new("Foo", @index).perform assert_equal(1, result.length) assert_equal(URI::Generic.from_path(path: path).to_s, T.must(result.first).location.uri) end @@ -77,7 +77,7 @@ class Bar; end end RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::Bar", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::Bar", @index).perform.first assert_equal("Foo::Bar", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CLASS, T.must(result).kind) assert_equal("Foo", T.must(result).container_name) @@ -86,7 +86,7 @@ class Bar; end def test_finds_default_gem_symbols @index.index_single(RubyIndexer::IndexablePath.new(nil, "#{RbConfig::CONFIG["rubylibdir"]}/pathname.rb")) - result = RubyLsp::Requests::WorkspaceSymbol.new("Pathname", @index).response + result = RubyLsp::Requests::WorkspaceSymbol.new("Pathname", @index).perform refute_empty(result) end @@ -98,7 +98,7 @@ class Foo end RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::CONSTANT", @index).response + result = RubyLsp::Requests::WorkspaceSymbol.new("Foo::CONSTANT", @index).perform assert_equal(1, result.length) assert_equal("Foo", T.must(result.first).name) end @@ -113,15 +113,15 @@ def bar; end end RUBY - result = RubyLsp::Requests::WorkspaceSymbol.new("bar", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("bar", @index).perform.first assert_equal("bar", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::METHOD, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("initialize", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("initialize", @index).perform.first assert_equal("initialize", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::CONSTRUCTOR, T.must(result).kind) - result = RubyLsp::Requests::WorkspaceSymbol.new("baz", @index).response.first + result = RubyLsp::Requests::WorkspaceSymbol.new("baz", @index).perform.first assert_equal("baz", T.must(result).name) assert_equal(RubyLsp::Constant::SymbolKind::PROPERTY, T.must(result).kind) end