Class: Rigor::LanguageServer::SignatureHelpProvider

Inherits:
Object
  • Object
show all
Includes:
BufferResolution
Defined in:
lib/rigor/language_server/signature_help_provider.rb

Overview

Answers textDocument/signatureHelp requests. When the user types ( inside a method call (obj.foo(|) editors fire signatureHelp to show the method's parameter signature inline. The provider parses the buffer, locates the enclosing CallNode, infers the receiver's type, and returns the method's first overload as a SignatureInformation.

Slice C1 (this commit) ships:

  • Sentinel patching for obj.foo(| so Prism's parse succeeds (mirrors CompletionProvider's slice B4 pattern).
  • First-overload signature only.
  • Active parameter = comma count before cursor.

Multi-overload presentation + documentation field + active-parameter override per overload land in follow-up slices (queued in the design doc ยง "Out of scope for v2").

Instance Method Summary collapse

Constructor Details

#initialize(buffer_table:, project_context:) ⇒ SignatureHelpProvider

Returns a new instance of SignatureHelpProvider.



41
42
43
44
# File 'lib/rigor/language_server/signature_help_provider.rb', line 41

def initialize(buffer_table:, project_context:)
  @buffer_table = buffer_table
  @project_context = project_context
end

Instance Method Details

#provide(uri:, line:, character:, context: nil) ⇒ Hash?

Returns LSP SignatureHelp payload or nil when the cursor isn't inside a resolvable method call.

Returns:

  • (Hash, nil)

    LSP SignatureHelp payload or nil when the cursor isn't inside a resolvable method call.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rigor/language_server/signature_help_provider.rb', line 48

def provide(uri:, line:, character:, context: nil)
  _ = context # Trigger info accepted but not routed in v1.
  path, entry = buffer_for(uri)
  return nil if entry.nil?

  bytes, locate_at = parse_attempt_bytes(entry.bytes, line, character)
  parse_result = Prism.parse(bytes, filepath: path,
                                    version: @project_context.configuration.target_ruby)
  return nil unless parse_result.errors.empty?

  cursor_offset = byte_offset_for(bytes, locate_at[0], locate_at[1])
  return nil if cursor_offset.nil?

  call_node = enclosing_call_for_offset(parse_result.value, cursor_offset)
  return nil if call_node.nil?

  build_signature(call_node, parse_result.value, path, bytes, locate_at[0], locate_at[1])
end