Class: RubyLsp::RSpec::IndexingEnhancement

Inherits:
RubyIndexer::Enhancement
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/ruby_lsp_rspec/indexing_enhancement.rb

Instance Method Summary collapse

Instance Method Details

#on_call_node_enter(owner, node, file_path, code_units_cache) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ruby_lsp/ruby_lsp_rspec/indexing_enhancement.rb', line 20

def on_call_node_enter(owner, node, file_path, code_units_cache)
  return if node.receiver

  name = node.name

  case name
  when :let, :let!
    block_node = node.block
    return unless block_node

    arguments = node.arguments
    return unless arguments

    return if arguments.arguments.count != 1

    method_name_node = T.must(arguments.arguments.first)

    method_name = case method_name_node
    when Prism::StringNode
      method_name_node.slice
    when Prism::SymbolNode
      method_name_node.unescaped
    end

    return unless method_name

    @index.add(RubyIndexer::Entry::Method.new(
      method_name,
      file_path,
      RubyIndexer::Location.from_prism_location(block_node.location, code_units_cache),
      RubyIndexer::Location.from_prism_location(block_node.location, code_units_cache),
      nil,
      [RubyIndexer::Entry::Signature.new([])],
      RubyIndexer::Entry::Visibility::PUBLIC,
      owner,
    ))
  when :subject, :subject!
    block_node = node.block
    return unless block_node

    arguments = node.arguments

    if arguments && arguments.arguments.count == 1
      method_name_node = T.must(arguments.arguments.first)
    end

    method_name = if method_name_node
      case method_name_node
      when Prism::StringNode
        method_name_node.slice
      when Prism::SymbolNode
        method_name_node.unescaped
      end
    else
      "subject"
    end

    return unless method_name

    @index.add(RubyIndexer::Entry::Method.new(
      method_name,
      file_path,
      RubyIndexer::Location.from_prism_location(block_node.location, code_units_cache),
      RubyIndexer::Location.from_prism_location(block_node.location, code_units_cache),
      nil,
      [RubyIndexer::Entry::Signature.new([])],
      RubyIndexer::Entry::Visibility::PUBLIC,
      owner,
    ))
  end
end