Class: RubyLsp::Runar::IndexingEnhancement

Inherits:
RubyIndexer::Enhancement
  • Object
show all
Defined in:
lib/ruby_lsp/runar/indexing.rb

Constant Summary collapse

PROP_METHOD_NAME =

: Symbol

:prop

Instance Method Summary collapse

Instance Method Details

#on_call_node_enter(node) ⇒ Object

Called by the LSP indexer for every CallNode encountered while parsing a file.

node - Prism::CallNode



33
34
35
36
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
# File 'lib/ruby_lsp/runar/indexing.rb', line 33

def on_call_node_enter(node)
  return unless runar_file?
  return unless node.name == PROP_METHOD_NAME
  return unless @listener.current_owner

  arguments = node.arguments&.arguments
  return unless arguments && arguments.length >= 2

  # First argument must be a symbol literal: prop :name, Type
  name_node = arguments[0]
  return unless name_node.is_a?(Prism::SymbolNode)

  prop_name = name_node.value
  return unless prop_name

  # Determine whether the call includes `readonly: true`.
  # We look for a keyword hash among the arguments.
  is_readonly = extract_readonly_keyword(arguments)

  # Register the reader method (always present).
  register_reader(prop_name, node)

  # Register the writer method only when the prop is not readonly.
  register_writer(prop_name, node) unless is_readonly

  # Register the backing instance variable so that @name is known
  # to the index for go-to-definition and hover.
  register_instance_variable("@#{prop_name}", node)
end

#on_call_node_leave(_node) ⇒ Object



64
# File 'lib/ruby_lsp/runar/indexing.rb', line 64

def on_call_node_leave(_node); end