class Solargraph::Shell
Public Instance Methods
available_cores()
click to toggle source
@deprecated
# File lib/solargraph/shell.rb, line 102 def available_cores puts 'The `available-cores` command is deprecated.' puts 'Current versions of Solargraph use RBS for core and stdlib documentation.' end
bundle()
click to toggle source
# File lib/solargraph/shell.rb, line 214 def bundle puts 'The `bundle` command is deprecated. Solargraph currently uses RBS instead.' end
clear()
click to toggle source
# File lib/solargraph/shell.rb, line 111 def clear puts "Deleting the cached documentation" Solargraph::Cache.clear end
config(directory = '.')
click to toggle source
# File lib/solargraph/shell.rb, line 52 def config(directory = '.') matches = [] if options[:extensions] Gem::Specification.each do |g| if g.name.match(/^solargraph\-[A-Za-z0-9_\-]*?\-ext/) require g.name matches.push g.name end end end conf = Solargraph::Workspace::Config.new.raw_data unless matches.empty? matches.each do |m| conf['extensions'].push m end end File.open(File.join(directory, '.solargraph.yml'), 'w') do |file| file.puts conf.to_yaml end STDOUT.puts "Configuration file initialized." end
download_core(_version = nil)
click to toggle source
@deprecated
# File lib/solargraph/shell.rb, line 80 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
list()
click to toggle source
# File lib/solargraph/shell.rb, line 200 def list workspace = Solargraph::Workspace.new(options[:directory]) unless options[:count] workspace.filenames.each { |f| puts f } end puts "#{workspace.filenames.length} files total." end
list_cores()
click to toggle source
@deprecated
# File lib/solargraph/shell.rb, line 91 def list_cores puts 'The `list-cores` command is deprecated.' puts 'Current versions of Solargraph use RBS for core and stdlib documentation.' end
rdoc(_gem, _version = '>= 0')
click to toggle source
# File lib/solargraph/shell.rb, line 222 def rdoc _gem, _version = '>= 0' puts 'The `rdoc` command is deprecated. Solargraph currently uses RBS instead.' end
reporters()
click to toggle source
# File lib/solargraph/shell.rb, line 130 def reporters puts Solargraph::Diagnostics.reporters end
scan()
click to toggle source
# File lib/solargraph/shell.rb, line 175 def scan require 'benchmark' directory = File.realpath(options[:directory]) api_map = nil time = Benchmark.measure { api_map = Solargraph::ApiMap.load(directory) api_map.pins.each do |pin| begin puts pin_description(pin) if options[:verbose] pin.typify api_map pin.probe api_map rescue StandardError => e STDERR.puts "Error testing #{pin_description(pin)} #{pin.location ? "at #{pin.location.filename}:#{pin.location.range.start.line + 1}" : ''}" STDERR.puts "[#{e.class}]: #{e.message}" STDERR.puts e.backtrace.join("\n") exit 1 end end } puts "Scanned #{directory} (#{api_map.pins.length} pins) in #{time.real} seconds." end
socket()
click to toggle source
# File lib/solargraph/shell.rb, line 19 def socket require 'backport' port = options[:port] port = available_port if port.zero? Backport.run do Signal.trap("INT") do Backport.stop end Signal.trap("TERM") do Backport.stop end Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}" end end
stdio()
click to toggle source
# File lib/solargraph/shell.rb, line 36 def stdio require 'backport' Backport.run do Signal.trap("INT") do Backport.stop end Signal.trap("TERM") do Backport.stop end Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}" end end
typecheck(*files)
click to toggle source
# File lib/solargraph/shell.rb, line 143 def typecheck *files directory = File.realpath(options[:directory]) api_map = Solargraph::ApiMap.load(directory) if files.empty? files = api_map.source_maps.map(&:filename) else files.map! { |file| File.realpath(file) } end probcount = 0 filecount = 0 files.each do |file| checker = TypeChecker.new(file, api_map: api_map, level: options[:level].to_sym) problems = checker.problems next if problems.empty? problems.sort! { |a, b| a.location.range.start.line <=> b.location.range.start.line } puts problems.map { |prob| "#{prob.location.filename}:#{prob.location.range.start.line + 1} - #{prob.message}" }.join("\n") filecount += 1 probcount += problems.length end puts "#{probcount} problem#{probcount != 1 ? 's' : ''} found#{files.length != 1 ? " in #{filecount} of #{files.length} files" : ''}." exit 1 if probcount > 0 end
uncache(*gems)
click to toggle source
# File lib/solargraph/shell.rb, line 119 def uncache *gems raise ArgumentError, 'No gems specified.' if gems.empty? gems.each do |gem| Dir[File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{gem}-*")].each do |dir| puts "Deleting cache: #{dir}" FileUtils.remove_entry_secure dir end end end
version()
click to toggle source
# File lib/solargraph/shell.rb, line 12 def version puts Solargraph::VERSION end
Private Instance Methods
pin_description(pin)
click to toggle source
@param pin [Solargraph::Pin::Base] @return [String]
# File lib/solargraph/shell.rb, line 230 def pin_description pin desc = if pin.path.nil? || pin.path.empty? if pin.closure "#{pin.closure.path} | #{pin.name}" else "#{pin.context.namespace} | #{pin.name}" end else pin.path end desc += " (#{pin.location.filename} #{pin.location.range.start.line})" if pin.location desc end