Skip to content

Commit

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

0 comments on commit 063b933

Please sign in to comment.