diff options
| author | Veetaha <gerzoh1@gmail.com> | 2020-03-14 03:01:14 +0200 |
|---|---|---|
| committer | Veetaha <gerzoh1@gmail.com> | 2020-03-14 03:01:14 +0200 |
| commit | 5e32a67c83d46862db0166c263efc65b6ecd5b52 (patch) | |
| tree | 9fbc81a8cfef4d9d76b29d23d63c6a3126ee8f8e /editors/code/src | |
| parent | d7b46e0527cd7b52845f37cffc57cbae4ba0b945 (diff) | |
| download | rust-5e32a67c83d46862db0166c263efc65b6ecd5b52.tar.gz rust-5e32a67c83d46862db0166c263efc65b6ecd5b52.zip | |
vscode-postrefactor: more logging and better error handling
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/config.ts | 36 | ||||
| -rw-r--r-- | editors/code/src/installation/extension.ts | 16 |
2 files changed, 30 insertions, 22 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 93f72409ddf..f63e1d20e85 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -1,7 +1,7 @@ import * as os from "os"; import * as vscode from 'vscode'; import { ArtifactSource } from "./installation/interfaces"; -import { log } from "./util"; +import { log, vscodeReloadWindow } from "./util"; const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; @@ -43,20 +43,20 @@ export class Config { ] .map(opt => `${this.rootSection}.${opt}`); + readonly packageJsonVersion = vscode + .extensions + .getExtension(this.extensionId)! + .packageJSON + .version as string; // n.n.YYYYMMDD[-nightly] + /** * Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release) */ readonly extensionReleaseTag: string = (() => { - const packageJsonVersion = vscode - .extensions - .getExtension(this.extensionId)! - .packageJSON - .version as string; // n.n.YYYYMMDD[-nightly] - - if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; + if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG; const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/; - const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!; + const [, yyyy, mm, dd] = this.packageJsonVersion.match(realVersionRegexp)!; return `${yyyy}-${mm}-${dd}`; })(); @@ -72,7 +72,10 @@ export class Config { this.cfg = vscode.workspace.getConfiguration(this.rootSection); const enableLogging = this.cfg.get("trace.extension") as boolean; log.setEnabled(enableLogging); - log.debug("Using configuration:", this.cfg); + log.debug( + "Extension version:", this.packageJsonVersion, + "using configuration:", this.cfg + ); } private async onConfigChange(event: vscode.ConfigurationChangeEvent) { @@ -90,7 +93,7 @@ export class Config { ); if (userResponse === "Reload now") { - vscode.commands.executeCommand("workbench.action.reloadWindow"); + await vscodeReloadWindow(); } } @@ -180,16 +183,11 @@ export class Config { } readonly installedNightlyExtensionReleaseDate = new DateStorage( - "rust-analyzer-installed-nightly-extension-release-date", + "installed-nightly-extension-release-date", this.ctx.globalState ); - readonly serverReleaseDate = new DateStorage( - "rust-analyzer-server-release-date", - this.ctx.globalState - ); - readonly serverReleaseTag = new Storage<null | string>( - "rust-analyzer-release-tag", this.ctx.globalState, null - ); + readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState); + readonly serverReleaseTag = new Storage<null | string>("server-release-tag", this.ctx.globalState, null); // We don't do runtime config validation here for simplicity. More on stackoverflow: // https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension diff --git a/editors/code/src/installation/extension.ts b/editors/code/src/installation/extension.ts index f6dd20d82d1..0d69b8d0cfe 100644 --- a/editors/code/src/installation/extension.ts +++ b/editors/code/src/installation/extension.ts @@ -44,10 +44,20 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve const currentExtReleaseDate = config.installedNightlyExtensionReleaseDate.get(); - assert(currentExtReleaseDate !== null, "nightly release date must've been set during installation"); + if (currentExtReleaseDate === null) { + void vscode.window.showErrorMessage( + "Nightly release date must've been set during the installation. " + + "Did you download and install the nightly .vsix package manually?" + ); + throw new Error("Nightly release date was not set in globalStorage"); + } - const hoursSinceLastUpdate = diffInHours(currentExtReleaseDate, new Date()); - log.debug(`Current rust-analyzer nightly was downloaded ${hoursSinceLastUpdate} hours ago`); + const dateNow = new Date; + const hoursSinceLastUpdate = diffInHours(currentExtReleaseDate, dateNow); + log.debug( + "Current rust-analyzer nightly was downloaded", hoursSinceLastUpdate, + "hours ago, namely:", currentExtReleaseDate, "and now is", dateNow + ); if (hoursSinceLastUpdate < HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS) { return; |
