]> git.lizzy.rs Git - rust.git/commitdiff
vscode-postrefactor: more logging and better error handling
authorVeetaha <gerzoh1@gmail.com>
Sat, 14 Mar 2020 01:01:14 +0000 (03:01 +0200)
committerVeetaha <gerzoh1@gmail.com>
Sat, 14 Mar 2020 01:01:14 +0000 (03:01 +0200)
editors/code/package-lock.json
editors/code/src/config.ts
editors/code/src/installation/extension.ts

index 575dc7c4a1f143d9a00df5dc2366fe51a4eb40eb..1b497edd7007813f975be4716164169cd353f382 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name": "rust-analyzer",
-    "version": "0.2.20200309-nightly",
+    "version": "0.2.20200309",
     "lockfileVersion": 1,
     "requires": true,
     "dependencies": {
index 93f72409ddfb9171151af66dd50327c3d9477e40..f63e1d20e850f8834bf2503c39df6b103095d0f7 100644 (file)
@@ -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
index f6dd20d82d1064821768fc45004041b369f21b1a..0d69b8d0cfe4541b8fef3c4894dfb74937753340 100644 (file)
@@ -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;