Repository: Shopify/ruby-lsp (Ruby)

Issue:
Signature Help handler - context param can be nil
### Ruby version

3.2.2,3.3.0

### Code snippet

_No response_

### Description

Currently using https://github.com/ray-x/lsp_signature.nvim neovim plugin to show signature help, and it seems that ruby-lsp expects a context param (https://github.com/Shopify/ruby-lsp/blob/main/lib/ruby_lsp/executor.rb#L176) that lsp_signature isn't passing: https://github.com/ray-x/lsp_signature.nvim/blob/master/lua/lsp_signature/init.lua#L686-L702

All thats being sent is `vim.lsp.util.make_position_params()`, which returns
```
{
  position = {
    character = 9,
    line = 175
  },
  textDocument = {
    uri = "file:///Users/cameron/.local/share/mise/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/executor.rb"
  }
}
```

According to the lsp spec for `signatureHelpParams` (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureHelpParams), context is _optional_, and should be opt-in by the client:
```
/**
	 * The signature help context. This is only available if the client
	 * specifies to send this using the client capability
	 * `textDocument.signatureHelp.contextSupport === true`
	 *
	 * @since 3.15.0
	 */
```


However, because ruby-lsp treats this param as non-optional, the following NoMethodError is raised:


```
lsp_signatur handler RPC[Error] code_name = InternalError, message = "#<NoMethodError: undefined method `[]' for nil:NilClass>" data = {
  backtrace = "

~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/executor.rb:254:in `signature_help'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11176/lib/types/private/methods/_methods.rb:274:in `bind_call'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11176/lib/types/private/methods/_methods.rb:274:in `block in _on_method_added'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/executor.rb:176:in `run'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/executor.rb:26:in `execute'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/server.rb:135:in `block (2 levels) in new_worker'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/server.rb:123:in `loop'
~/.local/share/mise/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/ruby-lsp-0.13.2/lib/ruby_lsp/server.rb:123:in `block in new_worker'

",
  errorClass = "NoMethodError",
  errorMessage = "undefined method `[]' for nil:NilClass"
}
```

(I formatted the backtrace for easier reading)

### Expected output

ruby-lsp should be able to handle when this optional parameter isn't passed.



Fix (patch):
diff --git a/lib/ruby_lsp/executor.rb b/lib/ruby_lsp/executor.rb
index ac112c9aa7..a598524984 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 7ee379ce74..4c52f7c102 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)