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

[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.
# 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 “‘
Constant Summary collapse
- ResponseType =
type_member { { fixed: T::Array[Interface::InlayHint] } }
- RESCUE_STRING_LENGTH =
T.let("rescue".length, Integer)
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(range, emitter, message_queue) ⇒ InlayHints
constructor
A new instance of InlayHints.
- #on_rescue(node) ⇒ Object
Methods inherited from Listener
Methods included from Support::Common
#create_code_lens, #full_constant_name, #range_from_syntax_tree_node, #visible?
Constructor Details
permalink #initialize(range, emitter, message_queue) ⇒ InlayHints
Returns a new instance of InlayHints.
33 34 35 36 37 38 39 40 |
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 33 def initialize(range, emitter, ) super(emitter, ) @response = T.let([], ResponseType) @range = range emitter.register(self, :on_rescue) end |
Instance Attribute Details
permalink #response ⇒ Object (readonly)
Returns the value of attribute response.
30 31 32 |
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 30 def response @response end |
Instance Method Details
permalink #on_rescue(node) ⇒ Object
[View source]
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby_lsp/requests/inlay_hints.rb', line 43 def on_rescue(node) exception = node.exception return unless exception.nil? || exception.exceptions.nil? loc = node.location return unless visible?(node, @range) @response << Interface::InlayHint.new( position: { line: loc.start_line - 1, character: loc.start_column + RESCUE_STRING_LENGTH }, label: "StandardError", padding_left: true, tooltip: "StandardError is implied in a bare rescue", ) end |