class Solargraph::Shell
def self.exit_on_failure?
def self.exit_on_failure? true end
def cache gem, version = nil
-
version
(String, nil
) -- -
gem
(String
) --
Returns:
-
(void)
-
def cache gem, version = nil spec = Gem::Specification.find_by_name(gem, version) pins = GemPins.build(spec) Cache.save('gems', "#{spec.name}-#{spec.version}.ser", pins) end
def clear
-
(void)
-
def clear puts "Deleting all cached documentation (gems, core and stdlib)" Solargraph::Cache.clear end
def config(directory = '.')
-
(void)
-
Parameters:
-
directory
(String
) --
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
def do_cache gemspec
-
(void)
-
Parameters:
-
gemspec
(Gem::Specification
) --
def do_cache gemspec cached = Yardoc.cached?(gemspec) if cached && !options.rebuild puts "Cache already exists for #{gemspec.name} #{gemspec.version}" else puts "#{cached ? 'Rebuilding' : 'Caching'} gem documentation for #{gemspec.name} #{gemspec.version}" pins = GemPins.build(gemspec) Cache.save('gems', "#{gemspec.name}-#{gemspec.version}.ser", pins) end end
def gems *names
-
(void)
-
def gems *names if names.empty? Gem::Specification.to_a.each { |spec| do_cache spec } else names.each do |name| spec = Gem::Specification.find_by_name(*name.split('=')) do_cache spec rescue Gem::MissingSpecError warn "Gem '#{name}' not found" end end end
def list
-
(void)
-
def list workspace = Solargraph::Workspace.new(options[:directory]) puts workspace.filenames unless options[:count] puts "#{workspace.filenames.length} files total." end
def pin_description pin
-
(String)
-
Parameters:
-
pin
(Solargraph::Pin::Base
) --
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
def reporters
-
(void)
-
def reporters puts Solargraph::Diagnostics.reporters end
def scan
-
(void)
-
def scan directory = File.realpath(options[:directory]) api_map = nil time = Benchmark.measure { api_map = Solargraph::ApiMap.load_with_cache(directory, $stdout) 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
def socket
-
(void)
-
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
def stdio
-
(void)
-
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
def typecheck *files
-
(void)
-
def typecheck *files directory = File.realpath(options[:directory]) api_map = Solargraph::ApiMap.load_with_cache(directory, $stdout) probcount = 0 if files.empty? files = api_map.source_maps.map(&:filename) else files.map! { |file| File.realpath(file) } end filecount = 0 time = Benchmark.measure { 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 "Typecheck finished in #{time.real} seconds." puts "#{probcount} problem#{probcount != 1 ? 's' : ''} found#{files.length != 1 ? " in #{filecount} of #{files.length} files" : ''}." # " exit 1 if probcount > 0 end
def uncache *gems
-
(void)
-
def uncache *gems raise ArgumentError, 'No gems specified.' if gems.empty? gems.each do |gem| if gem == 'core' Cache.uncache("core.ser") next end if gem == 'stdlib' Cache.uncache("stdlib") next end spec = Gem::Specification.find_by_name(gem) Cache.uncache('gems', "#{spec.name}-#{spec.version}.ser") Cache.uncache('gems', "#{spec.name}-#{spec.version}.yardoc") end end
def version
-
(void)
-
def version puts Solargraph::VERSION end