Skip to content

Commit

Permalink
Add ruby-lsp-check executable
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jul 12, 2023
1 parent ae88127 commit f416093
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ jobs:

- name: Run tests
run: bundle exec rake

- name: Run ruby-lsp-check
run: bundle exec ruby-lsp-check
3 changes: 2 additions & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ commands:
bundle exec rake check_visit_overrides &&
bundle exec srb tc &&
bin/rubocop &&
bin/test"
bin/test &&
bundle exec exe/ruby-lsp-check"
test:
syntax:
argument: file
Expand Down
62 changes: 62 additions & 0 deletions exe/ruby-lsp-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/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

require "sorbet-runtime"

begin
T::Configuration.default_checked_level = :never
T::Configuration.call_validation_error_handler = ->(*) {}
T::Configuration.inline_type_error_handler = ->(*) {}
T::Configuration.sig_validation_error_handler = ->(*) {}
rescue
nil
end

require_relative "../lib/ruby_lsp/internal"

RubyLsp::Extension.load_extensions

T::Utils.run_all_sig_blocks

files = Dir.glob("#{Dir.pwd}/**/*.rb")

puts "Verifying that all automatic LSP requests execute successfully. This may take a while..."

errors = {}
store = RubyLsp::Store.new
message_queue = Thread::Queue.new
executor = RubyLsp::Executor.new(store, message_queue)

files.each_with_index do |file, index|
uri = "file://#{file}"
store.set(uri: uri, source: File.read(file), version: 1)

# Executing any of the automatic requests will execute all of them, so here we just pick one
result = executor.execute({
method: "textDocument/documentSymbol",
params: { textDocument: { uri: uri } },
})

error = result.error
errors[file] = error if error
ensure
store.delete(uri)
print("\033[M\033[0KCompleted #{index + 1}/#{files.length}")
end

puts "\n"
message_queue.close

if errors.empty?
puts "All automatic LSP requests executed successfully"
exit
end

puts <<~ERRORS
Errors while executing requests:
#{errors.map { |file, error| "#{file}: #{error.message}" }.join("\n")}
ERRORS
exit!
2 changes: 1 addition & 1 deletion ruby-lsp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|

s.files = Dir.glob("lib/**/*.rb") + ["README.md", "VERSION", "LICENSE.txt"]
s.bindir = "exe"
s.executables = ["ruby-lsp"]
s.executables = ["ruby-lsp", "ruby-lsp-check"]
s.require_paths = ["lib"]

s.add_dependency("language_server-protocol", "~> 3.17.0")
Expand Down

0 comments on commit f416093

Please sign in to comment.