Class: Hind::LSIF::ReferenceVisitor

Inherits:
Prism::Visitor
  • Object
show all
Defined in:
lib/hind/lsif/visitors/reference_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator, file_path) ⇒ ReferenceVisitor

Returns a new instance of ReferenceVisitor.



8
9
10
11
12
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 8

def initialize(generator, file_path)
  @generator = generator
  @file_path = file_path
  @current_scope = []
end

Instance Attribute Details

#current_scopeObject (readonly)

Returns the value of attribute current_scope.



6
7
8
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 6

def current_scope
  @current_scope
end

Instance Method Details

#visit_class_node(node) ⇒ Object



43
44
45
46
47
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 43

def visit_class_node(node)
  @current_scope.push(node.constant_path.slice)
  super
  @current_scope.pop
end

#visit_constant_path_node(node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 30

def visit_constant_path_node(node)
  qualified_name = node.slice

  @generator.register_reference({
    type: :constant,
    name: qualified_name,
    node: node,
    scope: current_scope_name
  })

  super
end

#visit_constant_read_node(node) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 14

def visit_constant_read_node(node)
  return unless node.name

  constant_name = node.name.to_s
  qualified_name = @current_scope.empty? ? constant_name : "#{current_scope_name}::#{constant_name}"

  @generator.register_reference({
    type: :constant,
    name: qualified_name,
    node: node,
    scope: current_scope_name
  })

  super
end

#visit_module_node(node) ⇒ Object



49
50
51
52
53
# File 'lib/hind/lsif/visitors/reference_visitor.rb', line 49

def visit_module_node(node)
  @current_scope.push(node.constant_path.slice)
  super
  @current_scope.pop
end