Skip to content

Commit

Permalink
Ensure all ruby-lsp dependencies are installed before launch
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 16, 2024
1 parent d351687 commit b1c3d73
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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`,
);
}
}
Expand Down

0 comments on commit b1c3d73

Please sign in to comment.