Class: RubyLsp::Listeners::Definition

Inherits:
RubyLsp::Listener show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/ruby_lsp/listeners/definition.rb

Constant Summary collapse

ResponseType =
type_member { { fixed: T.nilable(T.any(T::Array[Interface::Location], Interface::Location)) } }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RubyLsp::Listener

#response

Methods included from Requests::Support::Common

#create_code_lens, #markdown_from_index_entries, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?, #visible?

Constructor Details

#initialize(uri, nesting, index, dispatcher, typechecker_enabled) ⇒ Definition

Returns a new instance of Definition.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby_lsp/listeners/definition.rb', line 24

def initialize(uri, nesting, index, dispatcher, typechecker_enabled)
  @uri = uri
  @nesting = nesting
  @index = index
  @typechecker_enabled = typechecker_enabled
  @_response = T.let(nil, ResponseType)

  super(dispatcher)

  dispatcher.register(
    self,
    :on_call_node_enter,
    :on_constant_read_node_enter,
    :on_constant_path_node_enter,
  )
end

Instance Attribute Details

#_responseObject (readonly)

Returns the value of attribute _response.



13
14
15
# File 'lib/ruby_lsp/listeners/definition.rb', line 13

def _response
  @_response
end

Instance Method Details

#on_call_node_enter(node) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ruby_lsp/listeners/definition.rb', line 42

def on_call_node_enter(node)
  message = node.name

  if message == :require || message == :require_relative
    handle_require_definition(node)
  else
    handle_method_definition(node)
  end
end

#on_constant_path_node_enter(node) ⇒ Object



53
54
55
# File 'lib/ruby_lsp/listeners/definition.rb', line 53

def on_constant_path_node_enter(node)
  find_in_index(node.slice)
end

#on_constant_read_node_enter(node) ⇒ Object



58
59
60
# File 'lib/ruby_lsp/listeners/definition.rb', line 58

def on_constant_read_node_enter(node)
  find_in_index(node.slice)
end