Class: Solargraph::YardMap

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/yard_map.rb,
lib/solargraph/yard_map/cache.rb,
lib/solargraph/yard_map/mapper.rb,
lib/solargraph/yard_map/core_gen.rb,
lib/solargraph/yard_map/core_docs.rb

Overview

The YardMap provides access to YARD documentation for the Ruby core, the stdlib, and gems.

Defined Under Namespace

Modules: CoreDocs, CoreGen Classes: Cache, Mapper

Constant Summary collapse

@@stdlib_yardoc =
CoreDocs.yardoc_stdlib_file
@@stdlib_paths =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(required: [], with_dependencies: true) ⇒ YardMap


32
33
34
35
36
37
38
39
40
# File 'lib/solargraph/yard_map.rb', line 32

def initialize(required: [], with_dependencies: true)
  # HACK: YardMap needs its own copy of this array
  @required = required.clone
  @with_dependencies = with_dependencies
  @gem_paths = {}
  @stdlib_namespaces = []
  process_requires
  yardocs.uniq!
end

Instance Attribute Details

#requiredArray<String> (readonly)


26
27
28
# File 'lib/solargraph/yard_map.rb', line 26

def required
  @required
end

#with_dependencies=(value) ⇒ Object (writeonly)

Sets the attribute with_dependencies


28
29
30
# File 'lib/solargraph/yard_map.rb', line 28

def with_dependencies=(value)
  @with_dependencies = value
end

Instance Method Details

#change(new_requires) ⇒ Boolean


54
55
56
57
58
59
60
61
62
63
# File 'lib/solargraph/yard_map.rb', line 54

def change new_requires
  if new_requires.uniq.sort == required.uniq.sort
    false
  else
    required.clear
    required.concat new_requires
    process_requires
    true
  end
end

#core_pinsArray<Solargraph::Pin::Base>


90
91
92
93
94
95
# File 'lib/solargraph/yard_map.rb', line 90

def core_pins
  @@core_pins ||= begin
    load_yardoc CoreDocs.yardoc_file
    Mapper.new(YARD::Registry.all).map
  end
end

#load_yardoc(y) ⇒ YARD::Registry


77
78
79
80
81
82
83
84
85
86
87
# File 'lib/solargraph/yard_map.rb', line 77

def load_yardoc y
  if y.kind_of?(Array)
    YARD::Registry.load y, true
  else
    YARD::Registry.load! y
  end
rescue Exception => e
  Solargraph::Logging.logger.warn "Error loading yardoc '#{y}' #{e.class} #{e.message}"
  yardocs.delete y
  nil
end

#path_pin(path) ⇒ Pin::Base


99
100
101
# File 'lib/solargraph/yard_map.rb', line 99

def path_pin path
  pins.select{ |p| p.path == path }.first
end

#pinsArray<Solargraph::Pin::Base>


43
44
45
# File 'lib/solargraph/yard_map.rb', line 43

def pins
  @pins ||= []
end

#require_reference(path) ⇒ Location

Get the location of a file referenced by a require path.


107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/solargraph/yard_map.rb', line 107

def require_reference path
  # @type [Gem::Specification]
  spec = Gem::Specification.find_by_path(path) || Gem::Specification.find_by_name(path.split('/').first)
  spec.full_require_paths.each do |rp|
    file = File.join(rp, "#{path}.rb")
    next unless File.file?(file)
    return Solargraph::Location.new(file, Solargraph::Range.from_to(0, 0, 0, 0))
  end
  nil
rescue Gem::LoadError
  nil
end

#unresolved_requiresArray<String>


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

def unresolved_requires
  @unresolved_requires ||= []
end

#with_dependencies?Boolean


47
48
49
50
# File 'lib/solargraph/yard_map.rb', line 47

def with_dependencies?
  @with_dependencies ||= true unless @with_dependencies == false
  @with_dependencies
end

#yardocsArray<String>


66
67
68
# File 'lib/solargraph/yard_map.rb', line 66

def yardocs
  @yardocs ||= []
end