Class: Solargraph::Shell
- Inherits:
-
Thor
- Object
- Thor
- Solargraph::Shell
- Includes:
- ServerMethods
- Defined in:
- lib/solargraph/shell.rb
Instance Method Summary collapse
- #available_cores ⇒ Object
- #clear_cores ⇒ Object
- #config(directory = '.') ⇒ Object
- #download_core(version = nil) ⇒ Object
- #list_cores ⇒ Object
- #reporters ⇒ Object
- #socket ⇒ Object
- #stdio ⇒ Object
- #suggest(*filenames) ⇒ Object
- #version ⇒ Object
Methods included from ServerMethods
Instance Method Details
#available_cores ⇒ Object
117 118 119 |
# File 'lib/solargraph/shell.rb', line 117 def available_cores puts Solargraph::YardMap::CoreDocs.available.join("\n") end |
#clear_cores ⇒ Object
122 123 124 |
# File 'lib/solargraph/shell.rb', line 122 def clear_cores Solargraph::YardMap::CoreDocs.clear end |
#config(directory = '.') ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/solargraph/shell.rb', line 82 def config(directory = '.') matches = [] if [: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) ⇒ Object
105 106 107 108 109 |
# File 'lib/solargraph/shell.rb', line 105 def download_core version = nil ver = version || Solargraph::YardMap::CoreDocs.best_download puts "Downloading docs for #{ver}..." Solargraph::YardMap::CoreDocs.download ver end |
#list_cores ⇒ Object
112 113 114 |
# File 'lib/solargraph/shell.rb', line 112 def list_cores puts Solargraph::YardMap::CoreDocs.versions.join("\n") end |
#reporters ⇒ Object
127 128 129 |
# File 'lib/solargraph/shell.rb', line 127 def reporters puts Solargraph::Diagnostics.reporters end |
#socket ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solargraph/shell.rb', line 22 def socket port = [:port] port = available_port if port.zero? EventMachine.run do Signal.trap("INT") do EventMachine.stop end Signal.trap("TERM") do EventMachine.stop end EventMachine.start_server [:host], port, Solargraph::LanguageServer::Transport::Socket # Emitted for the benefit of clients that start the process on port 0 STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}" end end |
#stdio ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/solargraph/shell.rb', line 39 def stdio EventMachine.run do Signal.trap("INT") do EventMachine.stop end Signal.trap("TERM") do EventMachine.stop end Solargraph::LanguageServer::Transport::Stdio.run STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}" end end |
#suggest(*filenames) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/solargraph/shell.rb', line 59 def suggest(*filenames) STDERR.puts "WARNING: The `solargraph suggest` command is a candidate for deprecation. It will either change drastically or not exist in a future version." # 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, 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
15 16 17 |
# File 'lib/solargraph/shell.rb', line 15 def version puts Solargraph::VERSION end |