Class: RubyLsp::Requests::InlayHints

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

Overview

![Inlay hint demo](../../inlay_hints.gif)

[Inlay hints](microsoft.github.io/language-server-protocol/specification#textDocument_inlayHint) are labels added directly in the code that explicitly show the user something that might otherwise just be implied.

# Configuration

To enable rescue hints, set ‘rubyLsp.featuresConfiguration.inlayHint.implicitRescue` to `true`.

To enable hash value hints, set ‘rubyLsp.featuresConfiguration.inlayHint.implicitHashValue` to `true`.

To enable all hints, set ‘rubyLsp.featuresConfiguration.inlayHint.enableAll` to `true`.

# Example

“‘ruby begin

puts "do something that might raise"

rescue # Label “StandardError” goes here as a bare rescue implies rescuing StandardError

puts "handle some rescue"

end “‘

# Example

“‘ruby var = “foo”

var: var, # Label "var" goes here in cases where the value is omitted
a: "hello",

“‘

Constant Summary collapse

ResponseType =
type_member { { fixed: T::Array[Interface::InlayHint] } }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, range, hints_configuration, dispatcher) ⇒ InlayHints

Returns a new instance of InlayHints.



64
65
66
67
68
69
70
71
72
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 64

def initialize(document, range, hints_configuration, dispatcher)
  super()
  start_line = range.dig(:start, :line)
  end_line = range.dig(:end, :line)
  @listener = T.let(
    Listeners::InlayHints.new(start_line..end_line, hints_configuration, dispatcher),
    Listener[ResponseType],
  )
end

Class Method Details

.providerObject



49
50
51
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 49

def provider
  Interface::InlayHintOptions.new(resolve_provider: false)
end

Instance Method Details

#performObject



75
76
77
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 75

def perform
  @listener.response
end