Class: RubyLsp::Requests::SignatureHelp

Inherits:
Request
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/requests/signature_help.rb

Overview

![Signature help demo](../../signature_help.gif)

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 bar(a, b, c)
end

def baz
  bar( # -> Signature help will show the parameters of `bar`
end

“‘

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, global_state, position, context, dispatcher, sorbet_level) ⇒ SignatureHelp

rubocop:disable Metrics/ParameterLists



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ruby_lsp/requests/signature_help.rb', line 52

def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
  super()
  node_context = document.locate_node(
    { line: position[:line], character: position[:character] },
    node_types: [Prism::CallNode],
  )

  target = adjust_for_nested_target(node_context.node, node_context.parent, position)

  @target = T.let(target, T.nilable(Prism::Node))
  @dispatcher = dispatcher
  @response_builder = T.let(ResponseBuilders::SignatureHelp.new, ResponseBuilders::SignatureHelp)
  Listeners::SignatureHelp.new(@response_builder, global_state, node_context, dispatcher, sorbet_level)
end

Class Method Details

.providerObject



34
35
36
37
38
39
# File 'lib/ruby_lsp/requests/signature_help.rb', line 34

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

#performObject



68
69
70
71
72
73
# File 'lib/ruby_lsp/requests/signature_help.rb', line 68

def perform
  return unless @target

  @dispatcher.dispatch_once(@target)
  @response_builder.response
end