Skip to content

Commit beb39e4

Browse files
authored
Merge pull request #811 from Shopify/vs/add_lsp_check
Add ruby-lsp-check executable
2 parents ae88127 + 089e780 commit beb39e4

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

.github/workflows/lsp_check.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: lsp_check
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
name: LSP check
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Set up Ruby
13+
uses: ruby/setup-ruby@v1
14+
with:
15+
ruby-version: "3.2"
16+
bundler-cache: true
17+
18+
- name: Run ruby-lsp-check
19+
run: bundle exec ruby-lsp-check

dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ commands:
2323
bundle exec rake check_visit_overrides &&
2424
bundle exec srb tc &&
2525
bin/rubocop &&
26-
bin/test"
26+
bin/test &&
27+
bundle exec exe/ruby-lsp-check"
2728
test:
2829
syntax:
2930
argument: file

exe/ruby-lsp-check

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# This executable checks if all automatic LSP requests run successfully on every Ruby file under the current directory
5+
6+
require "sorbet-runtime"
7+
8+
begin
9+
T::Configuration.default_checked_level = :never
10+
T::Configuration.call_validation_error_handler = ->(*) {}
11+
T::Configuration.inline_type_error_handler = ->(*) {}
12+
T::Configuration.sig_validation_error_handler = ->(*) {}
13+
rescue
14+
nil
15+
end
16+
17+
require_relative "../lib/ruby_lsp/internal"
18+
19+
RubyLsp::Extension.load_extensions
20+
21+
T::Utils.run_all_sig_blocks
22+
23+
files = Dir.glob("#{Dir.pwd}/**/*.rb")
24+
25+
puts "Verifying that all automatic LSP requests execute successfully. This may take a while..."
26+
27+
errors = {}
28+
store = RubyLsp::Store.new
29+
message_queue = Thread::Queue.new
30+
executor = RubyLsp::Executor.new(store, message_queue)
31+
32+
files.each_with_index do |file, index|
33+
uri = "file://#{file}"
34+
store.set(uri: uri, source: File.read(file), version: 1)
35+
36+
# Executing any of the automatic requests will execute all of them, so here we just pick one
37+
result = executor.execute({
38+
method: "textDocument/documentSymbol",
39+
params: { textDocument: { uri: uri } },
40+
})
41+
42+
error = result.error
43+
errors[file] = error if error
44+
ensure
45+
store.delete(uri)
46+
print("\033[M\033[0KCompleted #{index + 1}/#{files.length}") unless ENV["CI"]
47+
end
48+
49+
puts "\n"
50+
message_queue.close
51+
52+
if errors.empty?
53+
puts "All automatic LSP requests executed successfully"
54+
exit
55+
end
56+
57+
puts <<~ERRORS
58+
Errors while executing requests:
59+
60+
#{errors.map { |file, error| "#{file}: #{error.message}" }.join("\n")}
61+
ERRORS
62+
exit!

ruby-lsp.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414

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

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

0 commit comments

Comments
 (0)