From b1c3d7302a0d3588f7698de7943d0d1f0c892522 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 16 Oct 2024 16:55:33 -0400 Subject: [PATCH] Ensure all `ruby-lsp` dependencies are installed before launch --- vscode/src/workspace.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/vscode/src/workspace.ts b/vscode/src/workspace.ts index 1adcc6db0..8a537f3c1 100644 --- a/vscode/src/workspace.ts +++ b/vscode/src/workspace.ts @@ -133,6 +133,8 @@ export class Workspace implements WorkspaceInterface { debugMode, ); + // /opt/rubies/3.3.4/lib/ruby/site_ruby/3.3.0/rubygems/dependency.rb:301:in `to_specs': + // Could not find 'language_server-protocol'(~> 3.17.0) among 1544 total gem(s)(Gem:: MissingSpecError) try { STATUS_EMITTER.fire(this); await vscode.window.withProgress( @@ -225,13 +227,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 +267,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`, ); } }