1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/env ruby
# frozen_string_literal: true
# This executable checks if all automatic LSP requests run successfully on every Ruby file under the current directory
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
require "ruby_lsp/internal"
files = Dir.glob("#{Dir.pwd}/**/*.rb")
puts "Verifying that all automatic LSP requests execute successfully. This may take a while..."
errors = {}
server = RubyLsp::Server.new(test_mode: true)
files.each_with_index do |file, index|
uri = URI("file://#{file}")
server.process_message({
method: "textDocument/didOpen",
params: { textDocument: { uri: uri, text: File.read(file), version: 1 } },
})
# Executing any of the automatic requests will execute all of them, so here we just pick one
server.process_message({
id: 1,
method: "textDocument/documentSymbol",
params: { textDocument: { uri: uri } },
})
result = server.pop_response
errors[file] = result if result.is_a?(RubyLsp::Error)
ensure
server.process_message({ method: "textDocument/didClose", params: { textDocument: { uri: uri } } })
server.pop_response
print("\033[M\033[0KCompleted #{index + 1}/#{files.length}") unless ENV["CI"]
end
puts "\n"
# Indexing
puts "Verifying that indexing executes successfully. This may take a while..."
index = RubyIndexer::Index.new
uris = index.configuration.indexable_uris
uris.each_with_index do |uri, i|
index.index_file(uri)
rescue => e
errors[uri.full_path] = e
ensure
print("\033[M\033[0KIndexed #{i + 1}/#{uris.length}") unless ENV["CI"]
end
puts "\n"
if errors.empty?
puts "All operations completed successfully!"
exit
end
puts <<~ERRORS
Errors while executing:
#{errors.map { |file, error| "#{file}: #{error.message}" }.join("\n")}
ERRORS
exit!
|