Class: Hind::LSIF::DeclarationVisitor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator, file_path) ⇒ DeclarationVisitor

Returns a new instance of DeclarationVisitor.



8
9
10
11
12
# File 'lib/hind/lsif/visitors/declaration_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/declaration_visitor.rb', line 6

def current_scope
  @current_scope
end

Instance Method Details

#visit_class_node(node) ⇒ Object



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

def visit_class_node(node)
  @current_scope.push(node.constant_path.slice)
  class_name = current_scope_name

  @generator.register_declaration({
    type: :class,
    name: class_name,
    node: node,
    scope: @current_scope[0..-2].join('::'),
    superclass: node.superclass&.slice
  })

  super
  @current_scope.pop
end

#visit_constant_write_node(node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hind/lsif/visitors/declaration_visitor.rb', line 45

def visit_constant_write_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_declaration({
    type: :constant,
    name: qualified_name,
    node: node,
    scope: current_scope_name
  })

  super
end

#visit_module_node(node) ⇒ Object



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

def visit_module_node(node)
  @current_scope.push(node.constant_path.slice)
  module_name = current_scope_name

  @generator.register_declaration({
    type: :module,
    name: module_name,
    node: node,
    scope: @current_scope[0..-2].join('::')
  })

  super
  @current_scope.pop
end