Class: RubyLsp::Requests::SignatureHelp
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/ruby_lsp/requests/signature_help.rb
Overview

The [signature help request](microsoft.github.io/language-server-protocol/specification#textDocument_signatureHelp) displays information about the parameters of a method as you type an invocation.
Currently only supports methods invoked directly on ‘self` without taking inheritance into account.
# Example
“‘ruby class Foo
def (a, b, c)
end
def baz
( # -> Signature help will show the parameters of `bar`
end
“‘
Constant Summary collapse
- ResponseType =
type_member { { fixed: T.nilable(T.any(Interface::SignatureHelp, T::Hash[Symbol, T.untyped])) } }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document, index, position, context, dispatcher) ⇒ SignatureHelp
constructor
A new instance of SignatureHelp.
- #perform ⇒ Object
Constructor Details
#initialize(document, index, position, context, dispatcher) ⇒ SignatureHelp
Returns a new instance of SignatureHelp.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby_lsp/requests/signature_help.rb', line 54 def initialize(document, index, position, context, dispatcher) super() current_signature = context && context[:activeSignatureHelp] target, parent, nesting = document.locate_node( { line: position[:line], character: position[:character] - 2 }, node_types: [Prism::CallNode], ) # If we're typing a nested method call (e.g.: `foo(bar)`), then we may end up locating `bar` as the target # method call incorrectly. To correct that, we check if there's an active signature with the same name as the # parent node and then replace the target if current_signature && parent.is_a?(Prism::CallNode) active_signature = current_signature[:activeSignature] || 0 if current_signature.dig(:signatures, active_signature, :label)&.start_with?(parent.) target = parent end end @target = T.let(target, T.nilable(Prism::Node)) @dispatcher = dispatcher @listener = T.let(Listeners::SignatureHelp.new(nesting, index, dispatcher), Listener[ResponseType]) end |
Class Method Details
.provider ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ruby_lsp/requests/signature_help.rb', line 35 def provider # Identifier characters are automatically included, such as A-Z, a-z, 0-9, _, * or : Interface::SignatureHelpOptions.new( trigger_characters: ["(", " ", ","], ) end |
Instance Method Details
#perform ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ruby_lsp/requests/signature_help.rb', line 79 def perform return unless @target @dispatcher.dispatch_once(@target) @listener.response end |