Class: RubyLsp::Listeners::InlayHints
- Inherits:
-
Object
- Object
- RubyLsp::Listeners::InlayHints
- Includes:
- Requests::Support::Common
- Defined in:
- lib/ruby_lsp/listeners/inlay_hints.rb
Constant Summary collapse
- RESCUE_STRING_LENGTH =
: Integer
"rescue".length
Instance Method Summary collapse
-
#initialize(global_state, response_builder, dispatcher) ⇒ InlayHints
constructor
: (GlobalState, ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher) -> void.
-
#on_implicit_node_enter(node) ⇒ Object
: (Prism::ImplicitNode node) -> void.
-
#on_rescue_node_enter(node) ⇒ Object
: (Prism::RescueNode node) -> void.
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?
Constructor Details
#initialize(global_state, response_builder, dispatcher) ⇒ InlayHints
: (GlobalState, ResponseBuilders::CollectionResponseBuilder, Prism::Dispatcher) -> void
12 13 14 15 16 17 18 19 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 12 def initialize(global_state, response_builder, dispatcher) @response_builder = response_builder @hints_configuration = ( # rubocop:disable Style/RedundantParentheses global_state.feature_configuration(:inlayHint) #: as !nil ) #: RequestConfig dispatcher.register(self, :on_rescue_node_enter, :on_implicit_node_enter) end |
Instance Method Details
#on_implicit_node_enter(node) ⇒ Object
: (Prism::ImplicitNode node) -> void
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 37 def on_implicit_node_enter(node) return unless @hints_configuration.enabled?(:implicitHashValue) 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
: (Prism::RescueNode node) -> void
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_lsp/listeners/inlay_hints.rb', line 22 def on_rescue_node_enter(node) return unless @hints_configuration.enabled?(:implicitRescue) return unless node.exceptions.empty? loc = node.location @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 |