Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure update server gem command updates the locked server #2145

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ export class RubyLsp {
context.subscriptions.push(
vscode.commands.registerCommand(Command.Update, async () => {
const workspace = await this.showWorkspacePick();
await workspace?.installOrUpdateServer();

if (workspace) {
await workspace.installOrUpdateServer(true);
await workspace.restart();
}
}),
vscode.commands.registerCommand(Command.Start, async () => {
const workspace = await this.showWorkspacePick();
Expand Down
22 changes: 19 additions & 3 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class Workspace implements WorkspaceInterface {
}

try {
await this.installOrUpdateServer();
await this.installOrUpdateServer(false);
} catch (error: any) {
this.error = true;
await vscode.window.showErrorMessage(
Expand Down Expand Up @@ -175,7 +175,7 @@ export class Workspace implements WorkspaceInterface {

// Install or update the `ruby-lsp` gem globally with `gem install ruby-lsp` or `gem update ruby-lsp`. We only try to
// update on a daily basis, not every time the server boots
async installOrUpdateServer(): Promise<void> {
async installOrUpdateServer(manualInvocation: boolean): Promise<void> {
// If there's a user configured custom bundle to run the LSP, then we do not perform auto-updates and let the user
// manage that custom bundle themselves
const customBundle: string = vscode.workspace
Expand Down Expand Up @@ -210,8 +210,24 @@ export class Workspace implements WorkspaceInterface {
return;
}

// If we haven't updated the gem in the last 24 hours, update it
// In addition to updating the global installation of the ruby-lsp gem, if the user manually requested an update, we
// should delete the `.ruby-lsp` to ensure that we'll lock a new version of the server that will actually be booted
if (manualInvocation) {
try {
await vscode.workspace.fs.delete(
vscode.Uri.joinPath(this.workspaceFolder.uri, ".ruby-lsp"),
{ recursive: true },
);
} catch (error) {
this.outputChannel.info(
`Tried deleting ${vscode.Uri.joinPath(this.workspaceFolder.uri, ".ruby - lsp")}, but it doesn't exist`,
);
}
}

// If we haven't updated the gem in the last 24 hours or if the user manually asked for an update, update it
if (
manualInvocation ||
lastUpdatedAt === undefined ||
Date.now() - lastUpdatedAt > oneDayInMs
) {
Expand Down
Loading