diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index 02df8eac2..fb92a4644 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -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 diff --git a/test/integration_test.rb b/test/integration_test.rb index cc1d164c6..06667e64c 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -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" }) @@ -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