vscode-postrefactor: more logging and better error handling

This commit is contained in:
Veetaha 2020-03-14 03:01:14 +02:00
parent d7b46e0527
commit 5e32a67c83
3 changed files with 31 additions and 23 deletions

View file

@ -1,6 +1,6 @@
{
"name": "rust-analyzer",
"version": "0.2.20200309-nightly",
"version": "0.2.20200309",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View 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

View 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;