Skip to content

Commit

Permalink
Ensure update server gem command updates the locked server (#2145)
Browse files Browse the repository at this point in the history
* Ensure update server gem command updates the locked server

* Fix typo

Co-authored-by: Kaan Ozkan <[email protected]>

---------

Co-authored-by: Kaan Ozkan <[email protected]>
  • Loading branch information
vinistock and KaanOzkan authored Jun 7, 2024
1 parent 53cf57a commit 3a6fa2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 3a6fa2b

Please sign in to comment.