Skip to content

Commit 436e3a7

Browse files
authored
Fix signature help for clients that don't support the context param (#1285)
1 parent b492ae0 commit 436e3a7

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

lib/ruby_lsp/executor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ def perform_initial_indexing
247247
params(
248248
uri: URI::Generic,
249249
position: T::Hash[Symbol, T.untyped],
250-
context: T::Hash[Symbol, T.untyped],
250+
context: T.nilable(T::Hash[Symbol, T.untyped]),
251251
).returns(T.any(T.nilable(Interface::SignatureHelp), T::Hash[Symbol, T.untyped]))
252252
end
253253
def signature_help(uri, position, context)
254-
current_signature = context[:activeSignatureHelp]
254+
current_signature = context && context[:activeSignatureHelp]
255255
document = @store.get(uri)
256256
target, parent, nesting = document.locate_node(
257257
{ line: position[:line], character: position[:character] - 2 },
@@ -270,7 +270,7 @@ def signature_help(uri, position, context)
270270
end
271271

272272
dispatcher = Prism::Dispatcher.new
273-
listener = Requests::SignatureHelp.new(context, nesting, @index, dispatcher)
273+
listener = Requests::SignatureHelp.new(nesting, @index, dispatcher)
274274
dispatcher.dispatch_once(target)
275275
listener.response
276276
end

lib/ruby_lsp/requests/signature_help.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ def provider
4545

4646
sig do
4747
params(
48-
context: T::Hash[Symbol, T.untyped],
4948
nesting: T::Array[String],
5049
index: RubyIndexer::Index,
5150
dispatcher: Prism::Dispatcher,
5251
).void
5352
end
54-
def initialize(context, nesting, index, dispatcher)
55-
@context = context
53+
def initialize(nesting, index, dispatcher)
5654
@nesting = nesting
5755
@index = index
5856
@_response = T.let(nil, ResponseType)

test/requests/signature_help_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,37 @@ def baz
219219
assert_equal(1, result.active_parameter)
220220
end
221221

222+
def test_requests_missing_context
223+
document = RubyLsp::RubyDocument.new(source: +<<~RUBY, version: 1, uri: @uri)
224+
class Foo
225+
def bar(a, b)
226+
end
227+
228+
def baz
229+
bar()
230+
end
231+
end
232+
RUBY
233+
234+
@store.set(uri: @uri, source: document.source, version: 1)
235+
236+
index = @executor.instance_variable_get(:@index)
237+
index.index_single(RubyIndexer::IndexablePath.new(nil, @uri.to_standardized_path), document.source)
238+
239+
result = run_request(
240+
method: "textDocument/signatureHelp",
241+
params: {
242+
textDocument: { uri: @uri.to_s },
243+
position: { line: 5, character: 7 },
244+
},
245+
)
246+
247+
signature = result.signatures.first
248+
249+
assert_equal("bar(a, b)", signature.label)
250+
assert_equal(0, result.active_parameter)
251+
end
252+
222253
private
223254

224255
def run_request(method:, params: {})

0 commit comments

Comments
 (0)