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;
]
.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}`;
})();
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) {
);
if (userResponse === "Reload now") {
- vscode.commands.executeCommand("workbench.action.reloadWindow");
+ await vscodeReloadWindow();
}
}
}
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
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;