Skip to content

Commit

Permalink
Consolidate RuboCop feature loading
Browse files Browse the repository at this point in the history
Closes #2604
Alternative to #2605

This moves the two command CI checks into the test suite.
They would have cought this error, _expect_ rubocop is available to these.
So, create a seperate Gemfile that contains only the gem itself.
  • Loading branch information
Earlopain committed Sep 24, 2024
1 parent 63b702a commit 77dff24
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 42 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:

- name: Run tests
run: bundle exec rake

- name: Run index troubleshooting tool
run: bundle exec ruby-lsp --doctor
lint_node:
runs-on: ubuntu-latest
steps:
Expand Down
18 changes: 0 additions & 18 deletions .github/workflows/lsp_check.yml

This file was deleted.

4 changes: 1 addition & 3 deletions lib/ruby_lsp/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@
require "ruby_lsp/response_builders/signature_help"

# Request support
require "ruby_lsp/requests/support/rubocop_diagnostic"
require "ruby_lsp/requests/support/selection_range"
require "ruby_lsp/requests/support/annotation"
require "ruby_lsp/requests/support/sorbet"
require "ruby_lsp/requests/support/common"
require "ruby_lsp/requests/support/formatter"
require "ruby_lsp/requests/support/rubocop_runner"
require "ruby_lsp/requests/support/rubocop_formatter"
require "ruby_lsp/requests/support/syntax_tree_formatter"
require "ruby_lsp/requests/support/rubocop"

# Requests
require "ruby_lsp/requests/request"
Expand Down
22 changes: 22 additions & 0 deletions lib/ruby_lsp/requests/support/rubocop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# typed: strict
# frozen_string_literal: true

begin
require "rubocop"
rescue LoadError
return
end

begin
gem("rubocop", ">= 1.4.0")
rescue LoadError
raise StandardError, "Incompatible RuboCop version. Ruby LSP requires >= 1.4.0"
end

if RuboCop.const_defined?(:LSP) # This condition will be removed when requiring RuboCop >= 1.61.
RuboCop::LSP.enable
end

require "ruby_lsp/requests/support/rubocop_diagnostic"
require "ruby_lsp/requests/support/rubocop_runner"
require "ruby_lsp/requests/support/rubocop_formatter"
2 changes: 0 additions & 2 deletions lib/ruby_lsp/requests/support/rubocop_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# typed: strict
# frozen_string_literal: true

return unless defined?(RubyLsp::Requests::Support::RuboCopRunner)

module RubyLsp
module Requests
module Support
Expand Down
16 changes: 0 additions & 16 deletions lib/ruby_lsp/requests/support/rubocop_runner.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# typed: strict
# frozen_string_literal: true

begin
require "rubocop"
rescue LoadError
return
end

begin
gem("rubocop", ">= 1.4.0")
rescue LoadError
raise StandardError, "Incompatible RuboCop version. Ruby LSP requires >= 1.4.0"
end

if RuboCop.const_defined?(:LSP) # This condition will be removed when requiring RuboCop >= 1.61.
RuboCop::LSP.enable
end

module RubyLsp
module Requests
module Support
Expand Down
44 changes: 44 additions & 0 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# typed: true
# frozen_string_literal: true

require "test_helper"

class IntegrationTest < Minitest::Test
def test_ruby_lsp_doctor_works
skip("CI only") unless ENV["CI"]
in_isolation do
system("bundle exec ruby-lsp --doctor")
assert_equal(0, $CHILD_STATUS)
end
end

def test_ruby_lsp_check_works
skip("CI only") unless ENV["CI"]
in_isolation do
system("bundle exec ruby-lsp-check")
assert_equal(0, $CHILD_STATUS)
end
end

private

def in_isolation(&block)
gem_path = T.must(__dir__) + "/../"
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "ruby-lsp", path: "#{gem_path}"
# This causes ruby-lsp to run in its own directory without
# all the supplementary gems like rubocop
Dir.chdir("#{gem_path}")
GEMFILE

capture_subprocess_io do
Bundler.with_unbundled_env(&block)
end
end
end
end
end

0 comments on commit 77dff24

Please sign in to comment.