Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ruby-lsp-check executable #811

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/lsp_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: lsp_check

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
name: LSP check
steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true

- 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}") unless ENV["CI"]
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