Class: Solargraph::YardMap

Inherits:
Object
  • Object
show all
Includes:
ApiMap::BundlerMethods
Defined in:
lib/solargraph/yard_map.rb,
lib/solargraph/yard_map/cache.rb,
lib/solargraph/yard_map/mapper.rb,
lib/solargraph/yard_map/helpers.rb,
lib/solargraph/yard_map/to_method.rb,
lib/solargraph/yard_map/mapper/to_method.rb,
lib/solargraph/yard_map/mapper/to_constant.rb,
lib/solargraph/yard_map/mapper/to_namespace.rb

Overview

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

Defined Under Namespace

Modules: Helpers Classes: Cache, Mapper, NoYardocError, ToMethod

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiMap::BundlerMethods

require_from_bundle

Constructor Details

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

Returns a new instance of YardMap.

Parameters:

  • required (Array<String>, Set<String>) (defaults to: [])
  • directory (String) (defaults to: '')
  • source_gems (Array<String>, Set<String>) (defaults to: [])
  • with_dependencies (Boolean) (defaults to: true)


30
31
32
33
# File 'lib/solargraph/yard_map.rb', line 30

def initialize(required: [], directory: '', source_gems: [], with_dependencies: true)
  @with_dependencies = with_dependencies
  change required.to_set, directory, source_gems.to_set
end

Instance Attribute Details

#with_dependencies=(value) ⇒ Boolean (writeonly)

Returns:

  • (Boolean)


24
25
26
# File 'lib/solargraph/yard_map.rb', line 24

def with_dependencies=(value)
  @with_dependencies = value
end

Instance Method Details

#base_requiredObject



132
133
134
# File 'lib/solargraph/yard_map.rb', line 132

def base_required
  @base_required ||= Set.new
end

#change(new_requires, new_directory, new_source_gems) ⇒ Boolean

Parameters:

  • new_requires (Set<String>)

    Required paths to use for loading gems

  • new_directory (String)

    The workspace directory

  • new_source_gems (Set<String>)

    Gems under local development (i.e., part of the workspace)

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/solargraph/yard_map.rb', line 49

def change new_requires, new_directory, new_source_gems
  return false if new_requires == base_required && new_directory == @directory && new_source_gems == @source_gems
  @gem_paths = {}
  base_required.replace new_requires
  required.replace new_requires
  # HACK: Hardcoded YAML handling
  required.add 'psych' if new_requires.include?('yaml')
  @source_gems = new_source_gems
  @directory = new_directory
  process_requires
  @rebindable_method_names = nil
  @pin_class_hash = nil
  @pin_select_cache = {}
  pins.each { |p| p.source = :yard }
  true
end

#directoryObject



136
137
138
# File 'lib/solargraph/yard_map.rb', line 136

def directory
  @directory ||= ''
end

#load_yardoc(y) ⇒ YARD::Registry

Parameters:

  • y (String)

Returns:

  • (YARD::Registry)


97
98
99
100
101
102
103
104
105
106
107
# File 'lib/solargraph/yard_map.rb', line 97

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

#missing_docsArray<String>

Returns:

  • (Array<String>)


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

def missing_docs
  @missing_docs ||= []
end

#path_pin(path) ⇒ Pin::Base

Parameters:

  • path (String)

Returns:



111
112
113
# File 'lib/solargraph/yard_map.rb', line 111

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

#pinsArray<Solargraph::Pin::Base>

Returns:



36
37
38
# File 'lib/solargraph/yard_map.rb', line 36

def pins
  @pins ||= []
end

#rebindable_method_namesSet<String>

Returns:

  • (Set<String>)


67
68
69
70
71
72
73
# File 'lib/solargraph/yard_map.rb', line 67

def rebindable_method_names
  @rebindable_method_names ||= pins_by_class(Pin::Method)
    .select { |pin| pin.comments && pin.comments.include?('@yieldself') }
    .map(&:name)
    .concat(['instance_eval', 'instance_exec', 'class_eval', 'class_exec', 'module_eval', 'module_exec', 'define_method'])
    .to_set
end

#require_reference(path) ⇒ Location

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

Parameters:

  • path (String)

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/solargraph/yard_map.rb', line 119

def require_reference path
  # @type [Gem::Specification]
  spec = spec_for_require(path)
  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

#requiredSet<String>

Returns:

  • (Set<String>)


81
82
83
# File 'lib/solargraph/yard_map.rb', line 81

def required
  @required ||= Set.new
end

#unresolved_requiresArray<String>

Returns:

  • (Array<String>)


86
87
88
# File 'lib/solargraph/yard_map.rb', line 86

def unresolved_requires
  @unresolved_requires ||= []
end

#with_dependencies?Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/solargraph/yard_map.rb', line 40

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

#yardocsArray<String>

Returns:

  • (Array<String>)


76
77
78
# File 'lib/solargraph/yard_map.rb', line 76

def yardocs
  @yardocs ||= []
end