Class: RubyLsp::RSpec::Definition

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
RubyLsp::Requests::Support::Common
Defined in:
lib/ruby_lsp/ruby_lsp_rspec/definition.rb

Instance Method Summary collapse

Constructor Details

#initialize(response_builder, uri, node_context, index, dispatcher) ⇒ Definition

Returns a new instance of Definition.



23
24
25
26
27
28
29
# File 'lib/ruby_lsp/ruby_lsp_rspec/definition.rb', line 23

def initialize(response_builder, uri, node_context, index, dispatcher)
  @response_builder = response_builder
  @uri = uri
  @node_context = node_context
  @index = index
  dispatcher.register(self, :on_call_node_enter)
end

Instance Method Details

#on_call_node_enter(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby_lsp/ruby_lsp_rspec/definition.rb', line 32

def on_call_node_enter(node)
  message = node.message
  return unless message

  return if @node_context.locals_for_scope.include?(message)

  entries = @index[message]
  return unless entries
  return if entries.empty?

  entries.each do |entry|
    # Technically, let can be defined in a different file, but we're not going to handle that case yet
    next unless entry.file_path == @uri.to_standardized_path

    @response_builder << Interface::LocationLink.new(
      target_uri: URI::Generic.from_path(path: entry.file_path).to_s,
      target_range: range_from_location(entry.location),
      target_selection_range: range_from_location(entry.name_location),
    )
  end
end