mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 22:24:14 +00:00
vscode-postrefactor: more logging and better error handling
This commit is contained in:
parent
d7b46e0527
commit
5e32a67c83
3 changed files with 31 additions and 23 deletions
2
editors/code/package-lock.json
generated
2
editors/code/package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "rust-analyzer",
|
"name": "rust-analyzer",
|
||||||
"version": "0.2.20200309-nightly",
|
"version": "0.2.20200309",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { ArtifactSource } from "./installation/interfaces";
|
import { ArtifactSource } from "./installation/interfaces";
|
||||||
import { log } from "./util";
|
import { log, vscodeReloadWindow } from "./util";
|
||||||
|
|
||||||
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
||||||
|
|
||||||
|
@ -43,20 +43,20 @@ export class Config {
|
||||||
]
|
]
|
||||||
.map(opt => `${this.rootSection}.${opt}`);
|
.map(opt => `${this.rootSection}.${opt}`);
|
||||||
|
|
||||||
/**
|
readonly packageJsonVersion = vscode
|
||||||
* Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release)
|
|
||||||
*/
|
|
||||||
readonly extensionReleaseTag: string = (() => {
|
|
||||||
const packageJsonVersion = vscode
|
|
||||||
.extensions
|
.extensions
|
||||||
.getExtension(this.extensionId)!
|
.getExtension(this.extensionId)!
|
||||||
.packageJSON
|
.packageJSON
|
||||||
.version as string; // n.n.YYYYMMDD[-nightly]
|
.version as string; // n.n.YYYYMMDD[-nightly]
|
||||||
|
|
||||||
if (packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG;
|
/**
|
||||||
|
* Either `nightly` or `YYYY-MM-DD` (i.e. `stable` release)
|
||||||
|
*/
|
||||||
|
readonly extensionReleaseTag: string = (() => {
|
||||||
|
if (this.packageJsonVersion.endsWith(NIGHTLY_TAG)) return NIGHTLY_TAG;
|
||||||
|
|
||||||
const realVersionRegexp = /^\d+\.\d+\.(\d{4})(\d{2})(\d{2})/;
|
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}`;
|
return `${yyyy}-${mm}-${dd}`;
|
||||||
})();
|
})();
|
||||||
|
@ -72,7 +72,10 @@ export class Config {
|
||||||
this.cfg = vscode.workspace.getConfiguration(this.rootSection);
|
this.cfg = vscode.workspace.getConfiguration(this.rootSection);
|
||||||
const enableLogging = this.cfg.get("trace.extension") as boolean;
|
const enableLogging = this.cfg.get("trace.extension") as boolean;
|
||||||
log.setEnabled(enableLogging);
|
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) {
|
private async onConfigChange(event: vscode.ConfigurationChangeEvent) {
|
||||||
|
@ -90,7 +93,7 @@ export class Config {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (userResponse === "Reload now") {
|
if (userResponse === "Reload now") {
|
||||||
vscode.commands.executeCommand("workbench.action.reloadWindow");
|
await vscodeReloadWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,16 +183,11 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly installedNightlyExtensionReleaseDate = new DateStorage(
|
readonly installedNightlyExtensionReleaseDate = new DateStorage(
|
||||||
"rust-analyzer-installed-nightly-extension-release-date",
|
"installed-nightly-extension-release-date",
|
||||||
this.ctx.globalState
|
this.ctx.globalState
|
||||||
);
|
);
|
||||||
readonly serverReleaseDate = new DateStorage(
|
readonly serverReleaseDate = new DateStorage("server-release-date", this.ctx.globalState);
|
||||||
"rust-analyzer-server-release-date",
|
readonly serverReleaseTag = new Storage<null | string>("server-release-tag", this.ctx.globalState, null);
|
||||||
this.ctx.globalState
|
|
||||||
);
|
|
||||||
readonly serverReleaseTag = new Storage<null | string>(
|
|
||||||
"rust-analyzer-release-tag", this.ctx.globalState, null
|
|
||||||
);
|
|
||||||
|
|
||||||
// We don't do runtime config validation here for simplicity. More on stackoverflow:
|
// 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
|
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
|
||||||
|
|
|
@ -44,10 +44,20 @@ export async function ensureProperExtensionVersion(config: Config): Promise<neve
|
||||||
|
|
||||||
const currentExtReleaseDate = config.installedNightlyExtensionReleaseDate.get();
|
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());
|
const dateNow = new Date;
|
||||||
log.debug(`Current rust-analyzer nightly was downloaded ${hoursSinceLastUpdate} hours ago`);
|
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) {
|
if (hoursSinceLastUpdate < HEURISTIC_NIGHTLY_RELEASE_PERIOD_IN_HOURS) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue