Class: Steep::Drivers::Query
Constant Summary collapse
- LSP =
LanguageServer::Protocol
Instance Attribute Summary collapse
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(stdout:, stderr:) ⇒ Query
constructor
A new instance of Query.
- #run_definition(names:) ⇒ Object
- #run_diagnostics(paths:) ⇒ Object
- #run_hover(locations:) ⇒ Object
Constructor Details
#initialize(stdout:, stderr:) ⇒ Query
Returns a new instance of Query.
9 10 11 12 |
# File 'lib/steep/drivers/query.rb', line 9 def initialize(stdout:, stderr:) @stdout = stdout @stderr = stderr end |
Instance Attribute Details
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
7 8 9 |
# File 'lib/steep/drivers/query.rb', line 7 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/steep/drivers/query.rb', line 6 def stdout @stdout end |
Instance Method Details
#run_definition(names:) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/steep/drivers/query.rb', line 52 def run_definition(names:) unless Daemon.running? stderr.puts "Error: Steep server is not running. Start it with `steep server start` or `steep langserver`." return 1 end names.each do |name| request = { id: SecureRandom.uuid, method: Server::CustomMethods::Query__Definition::METHOD, params: { name: name } } result = send_request(request) stdout.puts JSON.generate({ name: name, result: result }) end 0 rescue Errno::ECONNREFUSED, Errno::ENOENT => e stderr.puts "Error: Failed to connect to Steep daemon: #{e.message}" 1 end |
#run_diagnostics(paths:) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/steep/drivers/query.rb', line 75 def run_diagnostics(paths:) unless Daemon.running? stderr.puts "Error: Steep server is not running. Start it with `steep server start` or `steep langserver`." return 1 end absolute_paths = [] #: Array[Pathname] paths.each do |path| pathname = Pathname(path) pathname = Pathname.pwd + pathname unless pathname.absolute? absolute_paths << pathname end request = { id: SecureRandom.uuid, method: Server::CustomMethods::Query__Diagnostics::METHOD, params: { paths: absolute_paths.empty? ? nil : absolute_paths.map(&:to_s) } } result = send_request(request) #: Array[{ uri: String, diagnostics: Array[untyped]? }]? (result || []).each do |entry| path = PathHelper.to_pathname(entry[:uri]) || Pathname(entry[:uri]) begin path = path.relative_path_from(Pathname.pwd) rescue ArgumentError # Keep the absolute path of files outside of the current directory end stdout.puts JSON.generate({ path: path.to_s, diagnostics: entry[:diagnostics] }) end 0 rescue Errno::ECONNREFUSED, Errno::ENOENT => e stderr.puts "Error: Failed to connect to Steep server: #{e.message}" 1 end |
#run_hover(locations:) ⇒ Object
16 17 18 19 20 21 22 23 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 |
# File 'lib/steep/drivers/query.rb', line 16 def run_hover(locations:) unless Daemon.running? stderr.puts "Error: Steep server is not running. Start it with `steep server start` or `steep langserver`." return 1 end locations.each do |path, line, column| absolute_path = to_absolute_path(path) unless absolute_path stdout.puts JSON.generate({ file: path, line: line, column: column, error: "File not found: #{path}" }) next end uri = PathHelper.to_uri(absolute_path).to_s request = { id: SecureRandom.uuid, method: "textDocument/hover", params: { textDocument: { uri: uri }, position: { line: line - 1, character: column - 1 } } } result = send_request(request) stdout.puts JSON.generate({ file: path, line: line, column: column, result: result }) end 0 rescue Errno::ECONNREFUSED, Errno::ENOENT => e stderr.puts "Error: Failed to connect to Steep daemon: #{e.message}" 1 end |