Rewrite auto-update

Everything now happens in main.ts, in the bootstrap family of
functions. The current flow is:

* check everything only on extension installation.
* if the user is on nightly channel, try to download the nightly
  extension and reload.
* when we install nightly extension, we persist its release id, so
  that we can check if the current release is different.
* if server binary was not downloaded by the current version of the
  extension, redownload it (we persist the version of ext that
  downloaded the server).
This commit is contained in:
Aleksey Kladov 2020-03-17 12:44:31 +01:00
parent f0a1b64d7e
commit fb6e655de8
13 changed files with 270 additions and 696 deletions

View file

@ -1,6 +1,5 @@
import * as lc from "vscode-languageclient";
import * as vscode from "vscode";
import { promises as dns } from "dns";
import { strict as nativeAssert } from "assert";
export function assert(condition: boolean, explanation: string): asserts condition {
@ -31,22 +30,6 @@ export const log = new class {
// eslint-disable-next-line no-console
console.error(message, ...optionalParams);
}
downloadError(err: Error, artifactName: string, repoName: string) {
vscode.window.showErrorMessage(
`Failed to download the rust-analyzer ${artifactName} from ${repoName} ` +
`GitHub repository: ${err.message}`
);
log.error(err);
dns.resolve('example.com').then(
addrs => log.debug("DNS resolution for example.com was successful", addrs),
err => log.error(
"DNS resolution for example.com failed, " +
"there might be an issue with Internet availability",
err
)
);
}
};
export async function sendRequestWithRetry<TParam, TRet>(
@ -86,17 +69,6 @@ function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export function notReentrant<TThis, TParams extends any[], TRet>(
fn: (this: TThis, ...params: TParams) => Promise<TRet>
): typeof fn {
let entered = false;
return function(...params) {
assert(!entered, `Reentrancy invariant for ${fn.name} is violated`);
entered = true;
return fn.apply(this, params).finally(() => entered = false);
};
}
export type RustDocument = vscode.TextDocument & { languageId: "rust" };
export type RustEditor = vscode.TextEditor & { document: RustDocument; id: string };
@ -110,29 +82,3 @@ export function isRustDocument(document: vscode.TextDocument): document is RustD
export function isRustEditor(editor: vscode.TextEditor): editor is RustEditor {
return isRustDocument(editor.document);
}
/**
* @param extensionId The canonical extension identifier in the form of: `publisher.name`
*/
export async function vscodeReinstallExtension(extensionId: string) {
// Unfortunately there is no straightforward way as of now, these commands
// were found in vscode source code.
log.debug("Uninstalling extension", extensionId);
await vscode.commands.executeCommand("workbench.extensions.uninstallExtension", extensionId);
log.debug("Installing extension", extensionId);
await vscode.commands.executeCommand("workbench.extensions.installExtension", extensionId);
}
export async function vscodeReloadWindow(): Promise<never> {
await vscode.commands.executeCommand("workbench.action.reloadWindow");
assert(false, "unreachable");
}
export async function vscodeInstallExtensionFromVsix(vsixPath: string) {
await vscode.commands.executeCommand(
"workbench.extensions.installExtension",
vscode.Uri.file(vsixPath)
);
}