Skip to content

Commit

Permalink
Fix signature help for clients that don't support the context param (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Jan 8, 2024
1 parent b492ae0 commit 436e3a7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/ruby_lsp/requests/signature_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ def provider

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)
Expand Down
31 changes: 31 additions & 0 deletions test/requests/signature_help_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {})
Expand Down

0 comments on commit 436e3a7

Please sign in to comment.