Skip to content

Commit

Permalink
Refactor mapping and caching
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide committed Dec 31, 2022
1 parent 866c019 commit cf1cd66
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 647 deletions.
2 changes: 0 additions & 2 deletions lib/solargraph.rb
Expand Up @@ -2,7 +2,6 @@

Encoding.default_external = 'UTF-8'

require 'solargraph/compat'
require 'solargraph/version'

# The top-level namespace for the Solargraph code mapping, documentation,
Expand Down Expand Up @@ -45,7 +44,6 @@ class InvalidRubocopVersionError < RuntimeError; end
autoload :Cache, 'solargraph/cache'

dir = File.dirname(__FILE__)
YARDOC_PATH = File.realpath(File.join(dir, '..', 'yardoc'))
YARD_EXTENSION_FILE = File.join(dir, 'yard-solargraph.rb')
VIEWS_PATH = File.join(dir, 'solargraph', 'views')

Expand Down
4 changes: 4 additions & 0 deletions lib/solargraph/cache.rb
Expand Up @@ -42,6 +42,10 @@ def save *path, pins
File.write file, ser, mode: 'wb'
true
end

def clear
FileUtils.rm_rf base_dir, secure: true
end
end
end
end
37 changes: 0 additions & 37 deletions lib/solargraph/compat.rb

This file was deleted.

Expand Up @@ -10,11 +10,7 @@ module Extended
#
class DownloadCore < Base
def process
ver = Solargraph::YardMap::CoreDocs.best_download
Solargraph::YardMap::CoreDocs.download ver
host.show_message "Downloaded documentation for Ruby #{ver}.", LanguageServer::MessageTypes::INFO
rescue StandardError => e
host.show_message "An error occurred while downloading documentation: [#{e.class}] #{e.message}", LanguageServer::MessageTypes::ERROR
host.show_message "Downloading cores is deprecated. Solargraph currently uses RBS for core and stdlib documentation", LanguageServer::MessageTypes::INFO
end
end
end
Expand Down
68 changes: 38 additions & 30 deletions lib/solargraph/shell.rb
Expand Up @@ -71,43 +71,47 @@ def config(directory = '.')
STDOUT.puts "Configuration file initialized."
end

desc 'download-core [VERSION]', 'Download core documentation'
def download_core version = nil
ver = version || Solargraph::YardMap::CoreDocs.best_download
if RUBY_VERSION != ver
puts "Documentation for #{RUBY_VERSION} is not available. Reverting to closest match..."
end
puts "Downloading docs for #{ver}..."
Solargraph::YardMap::CoreDocs.download ver
# Clear cached documentation if it exists
FileUtils.rm_rf Dir.glob(File.join(Solargraph::YardMap::CoreDocs.cache_dir, ver, '*.ser'))
puts "Download complete."
rescue ArgumentError => e
STDERR.puts "ERROR: #{e.message}"
STDERR.puts "Run `solargraph available-cores` for a list."
exit 1
desc 'download-core [VERSION]', 'Download core documentation [deprecated]'
long_desc %(
The `download-core` command is deprecated. Current versions of Solargraph
use RBS for core and stdlib documentation.
)
# @deprecated
def download_core _version = nil
puts 'The `download-core` command is deprecated.'
puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
end

desc 'list-cores', 'List the local documentation versions'
desc 'list-cores', 'List the local documentation versions [deprecated]'
long_desc %(
The `list-cores` command is deprecated. Current versions of Solargraph use
RBS for core and stdlib documentation.
)
# @deprecated
def list_cores
puts Solargraph::YardMap::CoreDocs.versions.join("\n")
puts 'The `list-cores` command is deprecated.'
puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
end

desc 'available-cores', 'List available documentation versions'
desc 'available-cores', 'List available documentation versions [deprecated]'
long_desc %(
The `available-cores` command is deprecated. Current versions of Solargraph
use RBS for core and stdlib documentation.
)
# @deprecated
def available_cores
puts Solargraph::YardMap::CoreDocs.available.join("\n")
puts 'The `available-cores` command is deprecated.'
puts 'Current versions of Solargraph use RBS for core and stdlib documentation.'
end

desc 'clear', 'Delete all cached documentation'
long_desc %(
This command will delete all core and gem documentation from the cache.
You can also delete specific gem caches with the `uncache` command or
update documentation for specific Ruby versions with the `download-core`
command.
)
# @deprecated
def clear
puts "Deleting the cached documentation"
Solargraph::YardMap::CoreDocs.clear
Solargraph::Cache.clear
end
map 'clear-cache' => :clear
map 'clear-cores' => :clear
Expand Down Expand Up @@ -191,18 +195,22 @@ def scan
puts "Scanned #{directory} (#{api_map.pins.length} pins) in #{time.real} seconds."
end

desc 'bundle', 'Generate documentation for bundled gems'
desc 'bundle', 'Generate documentation for bundled gems [deprecated]'
long_desc %(
The `bundle` command is deprecated. Solargraph currently uses RBS instead.
)
option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
option :rebuild, type: :boolean, aliases: :r, desc: 'Rebuild existing documentation', default: false
def bundle
Documentor.new(options[:directory], rebuild: options[:rebuild], out: STDOUT).document
puts 'The `bundle` command is deprecated. Solargraph currently uses RBS instead.'
end

desc 'rdoc GEM [VERSION]', 'Use RDoc to cache documentation'
def rdoc gem, version = '>= 0'
spec = Gem::Specification.find_by_name(gem, version)
puts "Caching #{spec.name} #{spec.version} from RDoc"
Solargraph::YardMap::RdocToYard.run(spec)
desc 'rdoc GEM [VERSION]', 'Use RDoc to cache documentation [deprecated]'
long_desc %(
The `rdoc` command is deprecated. Solargraph currently uses RBS instead.
)
def rdoc _gem, _version = '>= 0'
puts 'The `rdoc` command is deprecated. Solargraph currently uses RBS instead.'
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/solargraph/views/environment.erb
Expand Up @@ -30,10 +30,10 @@
Solargraph Version: <%= Solargraph::VERSION %>
</li>
<li>
Core Documentation Version: <%= Solargraph::YardMap::CoreDocs.best_match %>
Core Documentation Version: N/A <%# @todo Fix %>
</li>
<li>
Core Cache Directory: <%= Solargraph::YardMap::CoreDocs.cache_dir %>
Core Cache Directory: N/A <%# @todo Fix %>
</li>
<% unless Solargraph::Parser.rubyvm? %>
<li>
Expand Down
11 changes: 1 addition & 10 deletions lib/solargraph/yard_map.rb
Expand Up @@ -13,8 +13,6 @@ class YardMap
class NoYardocError < StandardError; end

autoload :Cache, 'solargraph/yard_map/cache'
autoload :CoreDocs, 'solargraph/yard_map/core_docs'
autoload :CoreGen, 'solargraph/yard_map/core_gen'
autoload :Mapper, 'solargraph/yard_map/mapper'
autoload :RdocToYard, 'solargraph/yard_map/rdoc_to_yard'
autoload :CoreFills, 'solargraph/yard_map/core_fills'
Expand Down Expand Up @@ -280,13 +278,7 @@ def process_yardoc y, spec = nil
# @param spec [Gem::Specification]
# @return [String]
def yardoc_file_for_spec spec
cache_dir = File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}", 'yardoc')
if File.exist?(cache_dir)
Solargraph.logger.info "Using cached documentation for #{spec.name} at #{cache_dir}"
cache_dir
else
YARD::Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
end
YARD::Registry.yardoc_file_for_gem(spec.name, "= #{spec.version}")
end

# @param path [String]
Expand All @@ -307,6 +299,5 @@ def spec_for_require path
end
spec
end

end
end
170 changes: 0 additions & 170 deletions lib/solargraph/yard_map/core_docs.rb

This file was deleted.

0 comments on commit cf1cd66

Please sign in to comment.