From 063b9332301b4c3dcaddbcd858875666deb9abc0 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 17 Oct 2024 09:43:47 -0400 Subject: [PATCH] Ensure all `ruby-lsp` dependencies are installed before launch (#2730) --- ruby-lsp.gemspec | 1 + vscode/src/workspace.ts | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ruby-lsp.gemspec b/ruby-lsp.gemspec index bcc8eaaca..45f0d9662 100644 --- a/ruby-lsp.gemspec +++ b/ruby-lsp.gemspec @@ -18,6 +18,7 @@ Gem::Specification.new do |s| s.executables = ["ruby-lsp", "ruby-lsp-check"] s.require_paths = ["lib"] + # Dependencies must be kept in sync with the checks in the extension side on workspace.ts s.add_dependency("language_server-protocol", "~> 3.17.0") s.add_dependency("prism", ">= 1.2", "< 2.0") s.add_dependency("rbs", ">= 3", "< 4") diff --git a/vscode/src/workspace.ts b/vscode/src/workspace.ts index 1adcc6db0..a5cb4cb8b 100644 --- a/vscode/src/workspace.ts +++ b/vscode/src/workspace.ts @@ -225,13 +225,24 @@ export class Workspace implements WorkspaceInterface { "rubyLsp.lastGemUpdate", ); - const { stdout } = await asyncExec("gem list ruby-lsp", { + // Theses are the Ruby LSP's own dependencies, listed in `ruby-lsp.gemspec` + const dependencies = [ + "ruby-lsp", + "language_server-protocol", + "prism", + "rbs", + "sorbet-runtime", + ]; + + const { stdout } = await asyncExec(`gem list ${dependencies.join(" ")}`, { cwd: this.workspaceFolder.uri.fsPath, env: this.ruby.env, }); - // If the gem is not yet installed, install it - if (!/^ruby-lsp[\s]/.exec(stdout)) { + // If any of the Ruby LSP's dependencies are missing, we need to install them. For example, if the user runs `gem + // uninstall prism`, then we must ensure it's installed or else rubygems will fail when trying to launch the + // executable + if (!dependencies.every((dep) => new RegExp(`${dep}\\s`).exec(stdout))) { await asyncExec("gem install ruby-lsp", { cwd: this.workspaceFolder.uri.fsPath, env: this.ruby.env, @@ -254,7 +265,7 @@ export class Workspace implements WorkspaceInterface { ); } catch (error) { this.outputChannel.info( - `Tried deleting ${vscode.Uri.joinPath(this.workspaceFolder.uri, ".ruby - lsp")}, but it doesn't exist`, + `Tried deleting ${vscode.Uri.joinPath(this.workspaceFolder.uri, ".ruby-lsp")}, but it doesn't exist`, ); } }