Class: Solargraph::LiveMap

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/live_map.rb,
lib/solargraph/live_map/cache.rb

Overview

The LiveMap allows extensions to add their own completion suggestions.

Defined Under Namespace

Classes: Cache

Constant Summary collapse

@@plugin_registry =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_map) ⇒ LiveMap

Returns a new instance of LiveMap.



12
13
14
15
# File 'lib/solargraph/live_map.rb', line 12

def initialize api_map
  @api_map = api_map
  runners
end

Instance Attribute Details

#api_map ⇒ Solargraph::ApiMap (readonly)

Returns:



10
11
12
# File 'lib/solargraph/live_map.rb', line 10

def api_map
  @api_map
end

Class Method Details

.install(cls) ⇒ Object

Deprecated.

See Solargraph::LiveMap.register instead

Register a plugin for LiveMap to use when generating suggestions.

Parameters:



80
81
82
# File 'lib/solargraph/live_map.rb', line 80

def self.install cls
  STDERR.puts "WARNING: The Solargraph::LiveMap.install procedure for installing plugins is no longer used. This operation will be ignored."
end

.plugins ⇒ Object

Deprecated.


90
91
92
93
# File 'lib/solargraph/live_map.rb', line 90

def self.plugins
  STDERR.puts "WARNING: Plugins have changed. The Solargraph::LiveMap.plugins attribute is no longer used."
  []
end

.register(name, klass) ⇒ Object

Raises:

  • (ArgumentError)


71
72
73
74
# File 'lib/solargraph/live_map.rb', line 71

def self.register name, klass
  raise ArgumentError.new("A Solargraph plugin named #{name} already exists") if @@plugin_registry.has_key?(name)
  @@plugin_registry[name] = klass
end

.uninstall(cls) ⇒ Object

Deprecated.


85
86
87
# File 'lib/solargraph/live_map.rb', line 85

def self.uninstall cls
  STDERR.puts "WARNING: The Solargraph::LiveMap.uninstall procedure for uninstalling plugins is no longer used. This operation will be ignored."
end

Instance Method Details

#get_constants(namespace, root = '') ⇒ Array<Solargraph::Suggestion>

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/solargraph/live_map.rb', line 35

def get_constants(namespace, root = '')
  cached = cache.get_constants(namespace, root)
  return cached unless cached.nil?
  did_runtime = false
  result = []
  runners.each do |p|
    next if did_runtime and p.runtime?
    result.concat p.get_constants(namespace, root)
    did_runtime = true if p.runtime?
  end
  suggestions = []
  result.uniq.each do |r|
    path = (r['namespace'].empty? ? '' : "#{r['namespace']}::") + r['name']
    kind = Suggestion::CONSTANT
    if r['class'] == 'Class'
      kind = Suggestion::CLASS
    elsif r['class'] == 'Module'
      kind = Suggestion::MODULE
    end
    suggestions.push(Suggestion.new(r['name'], kind: kind, path: path))
  end
  cache.set_constants(namespace, root, suggestions)
  suggestions
end

#get_fqns(namespace, root) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/solargraph/live_map.rb', line 60

def get_fqns(namespace, root)
  did_runtime = false
  runners.each do |p|
    next if did_runtime and p.runtime?
    result = p.get_fqns(namespace, root)
    return result unless result.nil?
    did_runtime = true if p.runtime?
  end
  nil
end

#get_methods(namespace, root = '', scope = 'instance', with_private = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/live_map.rb', line 17

def get_methods(namespace, root = '', scope = 'instance', with_private = false)
  params = {
    namespace: namespace, root: root, scope: scope, with_private: with_private
  }
  cached = cache.get_methods(params)
  return cached unless cached.nil?
  did_runtime = false
  result = []
  runners.each do |p|
    next if did_runtime and p.runtime?
    result.concat p.get_methods(namespace: namespace, root: root, scope: scope, with_private: with_private)
    did_runtime = true if p.runtime?
  end
  cache.set_methods(params, result)
  result
end

#refresh ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/solargraph/live_map.rb', line 95

def refresh
  changed = false
  runners.each do |p|
    changed ||= p.refresh
  end
  if changed
    STDERR.puts "Resetting LiveMap cache"
    cache.clear
    get_constants('')
    get_methods('', '', 'class')
    get_methods('', '', 'instance')
    get_methods('Kernel', '', 'class')
    get_methods('Kernel', '', 'instance')
  end
end