Module: Solargraph::Yardoc

Defined in:
lib/solargraph/yardoc.rb

Overview

Methods for caching and loading YARD documentation for gems.

Class Method Summary collapse

Class Method Details

.cache(yard_plugins, gemspec) ⇒ String

Build and cache a gem’s yardoc and return the path. If the cache already exists, do nothing and return the path.

Parameters:

  • yard_plugins (Array<String>)

    The names of YARD plugins to use.

  • gemspec (Gem::Specification)

Returns:

  • (String)

    The path to the cached yardoc.



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

def cache(yard_plugins, gemspec)
  path = PinCache.yardoc_path gemspec
  return path if cached?(gemspec)

  Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
  cmd = "yardoc --db #{path} --no-output --plugin solargraph"
  yard_plugins.each { |plugin| cmd << " --plugin #{plugin}" }
  Solargraph.logger.debug { "Running: #{cmd}" }
  # @todo set these up to run in parallel
  #
  # @sg-ignore RBS gem doesn't reflect that Open3.* also include
  #   kwopts from Process.spawn()
  stdout_and_stderr_str, status = Open3.capture2e(cmd, chdir: gemspec.gem_dir)
  unless status.success?
    Solargraph.logger.warn { "YARD failed running #{cmd.inspect} in #{gemspec.gem_dir}" }
    Solargraph.logger.info stdout_and_stderr_str
  end
  path
end

.cached?(gemspec) ⇒ Boolean

True if the gem yardoc is cached.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Boolean)


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

def cached?(gemspec)
  yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
  File.exist?(yardoc)
end

.load!(gemspec) ⇒ Array<YARD::CodeObjects::Base>

Note:

This method modifies the global YARD registry.

Load a gem’s yardoc and return its code objects.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Array<YARD::CodeObjects::Base>)


59
60
61
62
# File 'lib/solargraph/yardoc.rb', line 59

def load!(gemspec)
  YARD::Registry.load! PinCache.yardoc_path gemspec
  YARD::Registry.all
end

.processing?(gemspec) ⇒ Boolean

True if another process is currently building the yardoc cache.

Parameters:

  • gemspec (Gem::Specification)

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/solargraph/yardoc.rb', line 48

def processing?(gemspec)
  yardoc = File.join(PinCache.yardoc_path(gemspec), 'processing')
  File.exist?(yardoc)
end