Class: Hind::LSIF::GlobalState

Inherits:
Object
  • Object
show all
Defined in:
lib/hind/lsif/global_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobalState

Returns a new instance of GlobalState.



9
10
11
12
13
14
15
# File 'lib/hind/lsif/global_state.rb', line 9

def initialize
  @declarations = {}    # {qualified_name => {type:, node:, scope:, file:, range_id:, result_set_id:}}
  @references = {}      # {qualified_name => [{file:, range_id:, type:}, ...]}
  @result_sets = {}     # {qualified_name => result_set_id}
  @ranges = {}          # {file_path => [range_ids]}
  @project_id = nil
end

Instance Attribute Details

#declarationsObject (readonly)

Returns the value of attribute declarations.



7
8
9
# File 'lib/hind/lsif/global_state.rb', line 7

def declarations
  @declarations
end

#project_idObject

Returns the value of attribute project_id.



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

def project_id
  @project_id
end

#rangesObject (readonly)

Returns the value of attribute ranges.



7
8
9
# File 'lib/hind/lsif/global_state.rb', line 7

def ranges
  @ranges
end

#referencesObject (readonly)

Returns the value of attribute references.



7
8
9
# File 'lib/hind/lsif/global_state.rb', line 7

def references
  @references
end

#result_setsObject (readonly)

Returns the value of attribute result_sets.



7
8
9
# File 'lib/hind/lsif/global_state.rb', line 7

def result_sets
  @result_sets
end

Instance Method Details

#add_declaration(qualified_name, data) ⇒ Object



17
18
19
20
# File 'lib/hind/lsif/global_state.rb', line 17

def add_declaration(qualified_name, data)
  @declarations[qualified_name] = data
  @result_sets[qualified_name] = data[:result_set_id] if data[:result_set_id]
end

#add_range(file_path, range_id) ⇒ Object



31
32
33
34
# File 'lib/hind/lsif/global_state.rb', line 31

def add_range(file_path, range_id)
  @ranges[file_path] ||= []
  @ranges[file_path] << range_id
end

#add_reference(qualified_name, file_path, range_id, document_id) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/hind/lsif/global_state.rb', line 22

def add_reference(qualified_name, file_path, range_id, document_id)
  @references[qualified_name] ||= []
  @references[qualified_name] << {
    file: file_path,
    range_id: range_id,
    document_id: document_id
  }
end

#debug_infoObject



74
75
76
77
78
79
80
81
82
# File 'lib/hind/lsif/global_state.rb', line 74

def debug_info
  {
    declarations_count: @declarations.size,
    references_count: @references.values.sum(&:size),
    result_sets_count: @result_sets.size,
    ranges_count: @ranges.values.sum(&:size),
    declaration_types: declaration_types_count
  }
end

#find_constant_declaration(name, current_scope) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hind/lsif/global_state.rb', line 56

def find_constant_declaration(name, current_scope)
  return name if has_declaration?(name)

  if current_scope && !current_scope.empty?
    qualified_name = "#{current_scope}::#{name}"
    return qualified_name if has_declaration?(qualified_name)

    scope_parts = current_scope.split('::')
    while scope_parts.any?
      scope_parts.pop
      qualified_name = scope_parts.empty? ? name : "#{scope_parts.join("::")}::#{name}"
      return qualified_name if has_declaration?(qualified_name)
    end
  end

  has_declaration?(name) ? name : nil
end

#get_declaration(qualified_name) ⇒ Object



40
41
42
# File 'lib/hind/lsif/global_state.rb', line 40

def get_declaration(qualified_name)
  @declarations[qualified_name]
end

#get_ranges_for_file(file_path) ⇒ Object



52
53
54
# File 'lib/hind/lsif/global_state.rb', line 52

def get_ranges_for_file(file_path)
  @ranges[file_path] || []
end

#get_references(qualified_name) ⇒ Object



44
45
46
# File 'lib/hind/lsif/global_state.rb', line 44

def get_references(qualified_name)
  @references[qualified_name] || []
end

#get_result_set(qualified_name) ⇒ Object



48
49
50
# File 'lib/hind/lsif/global_state.rb', line 48

def get_result_set(qualified_name)
  @result_sets[qualified_name]
end

#has_declaration?(qualified_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/hind/lsif/global_state.rb', line 36

def has_declaration?(qualified_name)
  @declarations.key?(qualified_name)
end