From 4ba97820d75b723de17d567dcdcb13dce07e797b Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 8 Jan 2024 10:50:00 -0300 Subject: [PATCH] Fix signature help for clients that don't support the context param --- lib/ruby_lsp/executor.rb | 6 ++--- lib/ruby_lsp/requests/signature_help.rb | 4 +--- test/requests/signature_help_test.rb | 31 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/ruby_lsp/executor.rb b/lib/ruby_lsp/executor.rb index ac112c9aa..a59852498 100644 --- a/lib/ruby_lsp/executor.rb +++ b/lib/ruby_lsp/executor.rb @@ -247,11 +247,11 @@ def perform_initial_indexing params( uri: URI::Generic, position: T::Hash[Symbol, T.untyped], - context: T::Hash[Symbol, T.untyped], + context: T.nilable(T::Hash[Symbol, T.untyped]), ).returns(T.any(T.nilable(Interface::SignatureHelp), T::Hash[Symbol, T.untyped])) end def signature_help(uri, position, context) - current_signature = context[:activeSignatureHelp] + current_signature = context && context[:activeSignatureHelp] document = @store.get(uri) target, parent, nesting = document.locate_node( { line: position[:line], character: position[:character] - 2 }, @@ -270,7 +270,7 @@ def signature_help(uri, position, context) end dispatcher = Prism::Dispatcher.new - listener = Requests::SignatureHelp.new(context, nesting, @index, dispatcher) + listener = Requests::SignatureHelp.new(nesting, @index, dispatcher) dispatcher.dispatch_once(target) listener.response end diff --git a/lib/ruby_lsp/requests/signature_help.rb b/lib/ruby_lsp/requests/signature_help.rb index 7ee379ce7..4c52f7c10 100644 --- a/lib/ruby_lsp/requests/signature_help.rb +++ b/lib/ruby_lsp/requests/signature_help.rb @@ -33,14 +33,12 @@ class SignatureHelp < Listener sig do params( - context: T::Hash[Symbol, T.untyped], nesting: T::Array[String], index: RubyIndexer::Index, dispatcher: Prism::Dispatcher, ).void end - def initialize(context, nesting, index, dispatcher) - @context = context + def initialize(nesting, index, dispatcher) @nesting = nesting @index = index @_response = T.let(nil, ResponseType) diff --git a/test/requests/signature_help_test.rb b/test/requests/signature_help_test.rb index ec7c2637d..9d779019a 100644 --- a/test/requests/signature_help_test.rb +++ b/test/requests/signature_help_test.rb @@ -219,6 +219,37 @@ def baz assert_equal(1, result.active_parameter) end + def test_requests_missing_context + document = RubyLsp::RubyDocument.new(source: +<<~RUBY, version: 1, uri: @uri) + class Foo + def bar(a, b) + end + + def baz + bar() + end + end + RUBY + + @store.set(uri: @uri, source: document.source, version: 1) + + index = @executor.instance_variable_get(:@index) + index.index_single(RubyIndexer::IndexablePath.new(nil, @uri.to_standardized_path), document.source) + + result = run_request( + method: "textDocument/signatureHelp", + params: { + textDocument: { uri: @uri.to_s }, + position: { line: 5, character: 7 }, + }, + ) + + signature = result.signatures.first + + assert_equal("bar(a, b)", signature.label) + assert_equal(0, result.active_parameter) + end + private def run_request(method:, params: {})