Class: RubyLsp::Listeners::InlayHints
- Inherits:
-
Object
- Object
- RubyLsp::Listeners::InlayHints
- Extended by:
- T::Sig
- Includes:
- Requests::Support::Common
- Defined in:
- lib/ruby_lsp/listeners/inlay_hints.rb
Constant Summary collapse
- RESCUE_STRING_LENGTH =
T.let("rescue".length, Integer)
Instance Method Summary collapse
-
#initialize(response_builder, range, hints_configuration, dispatcher) ⇒ InlayHints
constructor
A new instance of InlayHints.
- #on_implicit_node_enter(node) ⇒ Object
- #on_rescue_node_enter(node) ⇒ Object
Methods included from Requests::Support::Common
#categorized_markdown_from_index_entries, #constant_name, #create_code_lens, #each_constant_path_part, #kind_for_entry, #markdown_from_index_entries, #namespace_constant_name, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?, #sorbet_level_true_or_higher?, #visible?
Constructor Details
#initialize(response_builder, range, hints_configuration, dispatcher) ⇒ InlayHints
Returns a new instance of InlayHints.
20 21 22 23 24 25 26 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 20 def initialize(response_builder, range, hints_configuration, dispatcher) @response_builder = response_builder @range = range @hints_configuration = hints_configuration dispatcher.register(self, :on_rescue_node_enter, :on_implicit_node_enter) end |
Instance Method Details
#on_implicit_node_enter(node) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 45 def on_implicit_node_enter(node) return unless @hints_configuration.enabled?(:implicitHashValue) return unless visible?(node, @range) node_value = node.value loc = node.location tooltip = "" node_name = "" case node_value when Prism::CallNode node_name = node_value.name tooltip = "This is a method call. Method name: #{node_name}" when Prism::ConstantReadNode node_name = node_value.name tooltip = "This is a constant: #{node_name}" when Prism::LocalVariableReadNode node_name = node_value.name tooltip = "This is a local variable: #{node_name}" end @response_builder << Interface::InlayHint.new( position: { line: loc.start_line - 1, character: loc.start_column + node_name.length + 1 }, label: node_name, padding_left: true, tooltip: tooltip, ) end |
#on_rescue_node_enter(node) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 29 def on_rescue_node_enter(node) return unless @hints_configuration.enabled?(:implicitRescue) return unless node.exceptions.empty? loc = node.location return unless visible?(node, @range) @response_builder << 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 |