Class: Solargraph::LiveMap
- Inherits:
-
Object
- Object
- Solargraph::LiveMap
- 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
- #api_map ⇒ Solargraph::ApiMap readonly
Class Method Summary collapse
Instance Method Summary collapse
- #get_constants(namespace, root = '') ⇒ Array<Solargraph::Pin::Base>
- #get_fqns(namespace, root) ⇒ Object
- #get_methods(namespace, root = '', scope = 'instance', with_private = false) ⇒ Array<Solargraph::Pin::Base>
- #get_path_pin(path) ⇒ Object
-
#initialize(api_map) ⇒ LiveMap
constructor
A new instance of LiveMap.
- #refresh ⇒ Object
Constructor Details
#initialize(api_map) ⇒ LiveMap
Returns a new instance of LiveMap.
13 14 15 16 |
# File 'lib/solargraph/live_map.rb', line 13 def initialize api_map @api_map = api_map runners end |
Instance Attribute Details
#api_map ⇒ Solargraph::ApiMap (readonly)
10 11 12 |
# File 'lib/solargraph/live_map.rb', line 10 def api_map @api_map end |
Class Method Details
.register(name, klass) ⇒ Object
81 82 83 84 |
# File 'lib/solargraph/live_map.rb', line 81 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 |
Instance Method Details
#get_constants(namespace, root = '') ⇒ Array<Solargraph::Pin::Base>
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 |
# File 'lib/solargraph/live_map.rb', line 44 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 = Pin::CONSTANT if r['class'] == 'Class' suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :class, :public, nil) elsif r['class'] == 'Module' suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :module, :public, nil) else suggestions.push Pin::Constant.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime"), nil, nil, nil, :public) end end cache.set_constants(namespace, root, suggestions) suggestions end |
#get_fqns(namespace, root) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/solargraph/live_map.rb', line 70 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) ⇒ Array<Solargraph::Pin::Base>
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/solargraph/live_map.rb', line 23 def get_methods(namespace, root = '', scope = 'instance', with_private = false) fqns = api_map.qualify(namespace, root) 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? p.get_methods(namespace: namespace, root: root, scope: scope, with_private: with_private).each do |m| result.push Solargraph::Pin::Method.new(nil, namespace, m['name'], YARD::Docstring.new('(defined at runtime)'), scope.to_sym, nil, []) end did_runtime = true if p.runtime? end cache.set_methods(params, result) result end |
#get_path_pin(path) ⇒ Object
18 19 20 |
# File 'lib/solargraph/live_map.rb', line 18 def get_path_pin path cache.get_path_pin(path) end |
#refresh ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/solargraph/live_map.rb', line 86 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 |