Class: Solargraph::Shell
- Inherits:
-
Thor
- Object
- Thor
- Solargraph::Shell
- Includes:
- ServerMethods
- Defined in:
- lib/solargraph/shell.rb
Instance Method Summary collapse
- #config(directory = '.') ⇒ Object
- #prepare ⇒ Object
- #server ⇒ Object
- #suggest(*filenames) ⇒ Object
- #version ⇒ Object
Methods included from ServerMethods
Instance Method Details
#config(directory = '.') ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/solargraph/shell.rb', line 100 def config(directory = '.') matches = [] if [:extensions] Gem::Specification.each do |g| puts g.name if g.name.match(/^solargraph\-[A-Za-z0-9_\-]*?\-ext/) require g.name matches.push g.name end end end conf = Solargraph::ApiMap::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 |
#prepare ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/solargraph/shell.rb', line 24 def prepare cache_dir = File.join(Dir.home, '.solargraph', 'cache') version_dir = File.join(cache_dir, '2.0.0') unless File.exist?(version_dir) or [:force] FileUtils.mkdir_p cache_dir puts 'Downloading 2.0.0...' Net::HTTP.start([:host]) do |http| resp = http.get("/2.0.0.tar.gz") open(File.join(cache_dir, '2.0.0.tar.gz'), "wb") do |file| file.write(resp.body) end puts 'Uncompressing archives...' FileUtils.rm_rf version_dir if File.exist?(version_dir) tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(File.join(cache_dir, '2.0.0.tar.gz'))) tar_extract.rewind tar_extract.each do |entry| if entry.directory? FileUtils.mkdir_p File.join(cache_dir, entry.full_name) else FileUtils.mkdir_p File.join(cache_dir, File.dirname(entry.full_name)) File.open(File.join(cache_dir, entry.full_name), 'wb') do |f| f << entry.read end end end tar_extract.close FileUtils.rm File.join(cache_dir, '2.0.0.tar.gz') puts 'Done.' end end end |
#server ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solargraph/shell.rb', line 60 def server port = [:port] port = available_port if port.zero? Solargraph::Server.set :port, port Solargraph::Server.set :views, [:views] unless [:views].nil? Solargraph::Server.set :public_folder, [:files] unless [:files].nil? Solargraph::Server.run! do STDERR.puts "Solargraph server pid=#{Process.pid} port=#{port}" end end |
#suggest(*filenames) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/solargraph/shell.rb', line 78 def suggest(*filenames) # HACK: The ARGV array needs to be manipulated for ARGF.read to work ARGV.clear ARGV.concat filenames text = ARGF.read filename = [:filename] || filenames[0] begin code_map = CodeMap.new(code: text, filename: filename) offset = code_map.get_offset([:line], [:column]) sugg = code_map.suggest_at(offset, with_snippets: true, filtered: true) result = { "status" => "ok", "suggestions" => sugg }.to_json STDOUT.puts result rescue Exception => e STDERR.puts e STDERR.puts e.backtrace.join("\n") result = { "status" => "err", "message" => e. + "\n" + e.backtrace.join("\n") }.to_json STDOUT.puts result end end |
#version ⇒ Object
17 18 19 |
# File 'lib/solargraph/shell.rb', line 17 def version puts Solargraph::VERSION end |