Skip to content

Commit 5e32a67

Browse files
author
Veetaha
committed
vscode-postrefactor: more logging and better error handling
1 parent d7b46e0 commit 5e32a67

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

editors/code/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editors/code/src/config.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as os from "os";
22
import * as vscode from 'vscode';
33
import { ArtifactSource } from "./installation/interfaces";
4-
import { log } from "./util";
4+
import { log, vscodeReloadWindow } from "./util";
55

66
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
77

@@ -43,20 +43,20 @@ export class Config {
4343
]
4444
.map(opt => `${this.rootSection}.${opt}`);
4545

46+
readonly packageJsonVersion = vscode
47+
.extensions
48+
.getExtension(this.extensionId)!
49+
.packageJSON
50+
.version as string; // n.n.YYYYMMDD[-nightly]
51+
4652
/**
4753
* Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release)
4854
*/
4955
readonly extensionReleaseTag: string = (() => {
50-
const packageJsonVersion = vscode
51-
.extensions
52-
.getExtension(this.extensionId)!
53-
.packageJSON
54-
.version as string; // n.n.YYYYMMDD[-nightly]
55-
56-
if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG;
56+
if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG;
5757

5858
const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/;
59-
const [, yyyy, mm, dd] = packageJsonVersion.match(realVersionRegexp)!;
59+
const [, yyyy, mm, dd] = this.packageJsonVersion.match(realVersionRegexp)!;
6060

6161
return `${yyyy}-${mm}-${dd}`;
6262
})();
@@ -72,7 +72,10 @@ export class Config {
7272
this.cfg = vscode.workspace.getConfiguration(this.rootSection);
7373
const enableLogging = this.cfg.get("trace.extension") as boolean;
7474
log.setEnabled(enableLogging);
75-
log.debug("Using configuration:", this.cfg);
75+
log.debug(
76+
"Extension version:", this.packageJsonVersion,
77+
"using configuration:", this.cfg
78+
);
7679
}
7780

7881
private async onConfigChange(event: vscode.ConfigurationChangeEvent) {
@@ -90,7 +93,7 @@ export class Config {
9093
);
9194

9295
if (userResponse === "Reload now") {
93-
vscode.commands.executeCommand("workbench.action.reloadWindow");
96+
await vscodeReloadWindow();
9497
}
9598
}
9699

@@ -180,16 +183,11 @@ export class Config {
180183
}
181184

182185
readonly installedNightlyExtensionReleaseDate = new DateStorage(
183-
"rust-analyzer-installed-nightly-extension-release-date",
186+
"installed-nightly-extension-release-date",
184187
this.ctx.globalState
185188
);
186-
readonly serverReleaseDate = new DateStorage(
187-
"rust-analyzer-server-release-date",
188-
this.ctx.globalState
189-
);
190-
readonly serverReleaseTag = new Storage<null | string>(
191-
"rust-analyzer-release-tag", this.ctx.globalState, null
192-
);
189+
readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState);
190+
readonly serverReleaseTag = new Storage<null | string>("server-release-tag", this.ctx.globalState, null);
193191

194192
// We don't do runtime config validation here for simplicity. More on stackoverflow:
195193
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension

editors/code/src/installation/extension.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve
4444

4545
const currentExtReleaseDate = config.installedNightlyExtensionReleaseDate.get();
4646

47-
assert(currentExtReleaseDate !== null, "nightly release date must've been set during installation");
47+
if (currentExtReleaseDate === null) {
48+
void vscode.window.showErrorMessage(
49+
"Nightly release date must've been set during the installation. " +
50+
"Did you download and install the nightly .vsix package manually?"
51+
);
52+
throw new Error("Nightly release date was not set in globalStorage");
53+
}
4854

49-
const hoursSinceLastUpdate = diffInHours(currentExtReleaseDate, new Date());
50-
log.debug(`Current rust-analyzer nightly was downloaded ${hoursSinceLastUpdate} hours ago`);
55+
const dateNow = new Date;
56+
const hoursSinceLastUpdate = diffInHours(currentExtReleaseDate, dateNow);
57+
log.debug(
58+
"Current rust-analyzer nightly was downloaded", hoursSinceLastUpdate,
59+
"hours ago, namely:", currentExtReleaseDate, "and now is", dateNow
60+
);
5161

5262
if (hoursSinceLastUpdate < HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS) {
5363
return;

0 commit comments

Comments
 (0)