Better releaseId naming
This commit is contained in:
parent
be3e997ddf
commit
230ed3304a
@ -157,7 +157,7 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
|
|||||||
await fs.mkdir(config.globalStoragePath, { recursive: true });
|
await fs.mkdir(config.globalStoragePath, { recursive: true });
|
||||||
|
|
||||||
if (config.package.releaseTag != NIGHTLY_TAG) {
|
if (config.package.releaseTag != NIGHTLY_TAG) {
|
||||||
await state.removeReleaseId();
|
await state.removeNightlyReleaseId();
|
||||||
}
|
}
|
||||||
await bootstrapExtension(config, state);
|
await bootstrapExtension(config, state);
|
||||||
const path = await bootstrapServer(config, state);
|
const path = await bootstrapServer(config, state);
|
||||||
@ -184,7 +184,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||||||
const lastCheck = state.lastCheck;
|
const lastCheck = state.lastCheck;
|
||||||
|
|
||||||
const anHour = 60 * 60 * 1000;
|
const anHour = 60 * 60 * 1000;
|
||||||
const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour;
|
const shouldCheckForNewNightly = state.nightlyReleaseId === undefined || (now - (lastCheck ?? 0)) > anHour;
|
||||||
|
|
||||||
if (!shouldCheckForNewNightly) return;
|
if (!shouldCheckForNewNightly) return;
|
||||||
}
|
}
|
||||||
@ -193,19 +193,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||||||
return await fetchRelease("nightly", state.githubToken, config.httpProxy);
|
return await fetchRelease("nightly", state.githubToken, config.httpProxy);
|
||||||
}).catch(async (e) => {
|
}).catch(async (e) => {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
if (state.releaseId === undefined) { // Show error only for the initial download
|
if (state.nightlyReleaseId === undefined) { // Show error only for the initial download
|
||||||
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
|
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
if (release === undefined) {
|
if (release === undefined) {
|
||||||
if (state.releaseId === undefined) { // Show error only for the initial download
|
if (state.nightlyReleaseId === undefined) { // Show error only for the initial download
|
||||||
await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
|
await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// If currently used extension is nightly and its release id matches the downloaded release id, we're already on the latest nightly version
|
if (config.package.releaseTag === NIGHTLY_TAG && release.id === state.nightlyReleaseId) return;
|
||||||
if (config.package.releaseTag === NIGHTLY_TAG && release.id === state.releaseId) return;
|
|
||||||
|
|
||||||
const userResponse = await vscode.window.showInformationMessage(
|
const userResponse = await vscode.window.showInformationMessage(
|
||||||
"New version of rust-analyzer (nightly) is available (requires reload).",
|
"New version of rust-analyzer (nightly) is available (requires reload).",
|
||||||
@ -230,7 +229,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||||||
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
||||||
await fs.unlink(dest);
|
await fs.unlink(dest);
|
||||||
|
|
||||||
await state.updateReleaseId(release.id);
|
await state.updateNightlyReleaseId(release.id);
|
||||||
await state.updateLastCheck(now);
|
await state.updateLastCheck(now);
|
||||||
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
await vscode.commands.executeCommand("workbench.action.reloadWindow");
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@ import { log } from './util';
|
|||||||
|
|
||||||
export class PersistentState {
|
export class PersistentState {
|
||||||
constructor(private readonly globalState: vscode.Memento) {
|
constructor(private readonly globalState: vscode.Memento) {
|
||||||
const { lastCheck, releaseId, serverVersion } = this;
|
const { lastCheck, nightlyReleaseId, serverVersion } = this;
|
||||||
log.info("PersistentState:", { lastCheck, releaseId, serverVersion });
|
log.info("PersistentState:", { lastCheck, nightlyReleaseId, serverVersion });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,13 +21,13 @@ export class PersistentState {
|
|||||||
* Release id of the *nightly* extension.
|
* Release id of the *nightly* extension.
|
||||||
* Used to check if we should update.
|
* Used to check if we should update.
|
||||||
*/
|
*/
|
||||||
get releaseId(): number | undefined {
|
get nightlyReleaseId(): number | undefined {
|
||||||
return this.globalState.get("releaseId");
|
return this.globalState.get("releaseId");
|
||||||
}
|
}
|
||||||
async updateReleaseId(value: number) {
|
async updateNightlyReleaseId(value: number) {
|
||||||
await this.globalState.update("releaseId", value);
|
await this.globalState.update("releaseId", value);
|
||||||
}
|
}
|
||||||
async removeReleaseId() {
|
async removeNightlyReleaseId() {
|
||||||
await this.globalState.update("releaseId", undefined);
|
await this.globalState.update("releaseId", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user