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

Check if RuboCop is available before searching for add-on #3071

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
3 changes: 2 additions & 1 deletion lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def apply_options(options)
@workspace_uri = URI(workspace_uri) if workspace_uri

specified_formatter = options.dig(:initializationOptions, :formatter)
rubocop_has_addon = Gem::Requirement.new(">= 1.70.0").satisfied_by?(Gem::Version.new(::RuboCop::Version::STRING))
rubocop_has_addon = defined?(::RuboCop::Version::STRING) &&
Gem::Requirement.new(">= 1.70.0").satisfied_by?(Gem::Version.new(::RuboCop::Version::STRING))

if specified_formatter
@formatter = specified_formatter
Expand Down
13 changes: 13 additions & 0 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ def launch(workspace_path, exec = "ruby-lsp-launcher", extra_env = {})
workspaceFolders: [{ uri: URI::Generic.from_path(path: workspace_path).to_s }],
},
})

# First message is the log of initializing Ruby LSP
read_message(stdout)
# Verify that initialization didn't fail
initialize_response = read_message(stdout)
refute(initialize_response[:error], initialize_response.dig(:error, :message))

send_message(stdin, { id: 2, method: "shutdown" })
send_message(stdin, { method: "exit" })

Expand Down Expand Up @@ -253,6 +260,12 @@ def send_message(stdin, message)
stdin.flush
end

def read_message(stdout)
headers = stdout.gets("\r\n\r\n")
length = headers[/Content-Length: (\d+)/i, 1].to_i
JSON.parse(stdout.read(length), symbolize_names: true)
end

def in_temp_dir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down
Loading