aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/main.ts13
-rw-r--r--editors/code/src/persistent_state.ts10
2 files changed, 11 insertions, 12 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 5db66df93..6ed8b6146 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -157,7 +157,7 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
157 await fs.mkdir(config.globalStoragePath, { recursive: true }); 157 await fs.mkdir(config.globalStoragePath, { recursive: true });
158 158
159 if (config.package.releaseTag != NIGHTLY_TAG) { 159 if (config.package.releaseTag != NIGHTLY_TAG) {
160 await state.removeReleaseId(); 160 await state.removeNightlyReleaseId();
161 } 161 }
162 await bootstrapExtension(config, state); 162 await bootstrapExtension(config, state);
163 const path = await bootstrapServer(config, state); 163 const path = await bootstrapServer(config, state);
@@ -184,7 +184,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
184 const lastCheck = state.lastCheck; 184 const lastCheck = state.lastCheck;
185 185
186 const anHour = 60 * 60 * 1000; 186 const anHour = 60 * 60 * 1000;
187 const shouldCheckForNewNightly = state.releaseId === undefined || (now - (lastCheck ?? 0)) > anHour; 187 const shouldCheckForNewNightly = state.nightlyReleaseId === undefined || (now - (lastCheck ?? 0)) > anHour;
188 188
189 if (!shouldCheckForNewNightly) return; 189 if (!shouldCheckForNewNightly) return;
190 } 190 }
@@ -193,19 +193,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
193 return await fetchRelease("nightly", state.githubToken, config.httpProxy); 193 return await fetchRelease("nightly", state.githubToken, config.httpProxy);
194 }).catch(async (e) => { 194 }).catch(async (e) => {
195 log.error(e); 195 log.error(e);
196 if (state.releaseId === undefined) { // Show error only for the initial download 196 if (state.nightlyReleaseId === undefined) { // Show error only for the initial download
197 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`); 197 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
198 } 198 }
199 return; 199 return;
200 }); 200 });
201 if (release === undefined) { 201 if (release === undefined) {
202 if (state.releaseId === undefined) { // Show error only for the initial download 202 if (state.nightlyReleaseId === undefined) { // Show error only for the initial download
203 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned"); 203 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
204 } 204 }
205 return; 205 return;
206 } 206 }
207 // If currently used extension is nightly and its release id matches the downloaded release id, we're already on the latest nightly version 207 if (config.package.releaseTag === NIGHTLY_TAG && release.id === state.nightlyReleaseId) return;
208 if (config.package.releaseTag === NIGHTLY_TAG && release.id === state.releaseId) return;
209 208
210 const userResponse = await vscode.window.showInformationMessage( 209 const userResponse = await vscode.window.showInformationMessage(
211 "New version of rust-analyzer (nightly) is available (requires reload).", 210 "New version of rust-analyzer (nightly) is available (requires reload).",
@@ -230,7 +229,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
230 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); 229 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
231 await fs.unlink(dest); 230 await fs.unlink(dest);
232 231
233 await state.updateReleaseId(release.id); 232 await state.updateNightlyReleaseId(release.id);
234 await state.updateLastCheck(now); 233 await state.updateLastCheck(now);
235 await vscode.commands.executeCommand("workbench.action.reloadWindow"); 234 await vscode.commands.executeCommand("workbench.action.reloadWindow");
236} 235}
diff --git a/editors/code/src/persistent_state.ts b/editors/code/src/persistent_state.ts
index 2519bd77a..c02eb2ca3 100644
--- a/editors/code/src/persistent_state.ts
+++ b/editors/code/src/persistent_state.ts
@@ -3,8 +3,8 @@ import { log } from './util';
3 3
4export class PersistentState { 4export class PersistentState {
5 constructor(private readonly globalState: vscode.Memento) { 5 constructor(private readonly globalState: vscode.Memento) {
6 const { lastCheck, releaseId, serverVersion } = this; 6 const { lastCheck, nightlyReleaseId, serverVersion } = this;
7 log.info("PersistentState:", { lastCheck, releaseId, serverVersion }); 7 log.info("PersistentState:", { lastCheck, nightlyReleaseId, serverVersion });
8 } 8 }
9 9
10 /** 10 /**
@@ -21,13 +21,13 @@ export class PersistentState {
21 * Release id of the *nightly* extension. 21 * Release id of the *nightly* extension.
22 * Used to check if we should update. 22 * Used to check if we should update.
23 */ 23 */
24 get releaseId(): number | undefined { 24 get nightlyReleaseId(): number | undefined {
25 return this.globalState.get("releaseId"); 25 return this.globalState.get("releaseId");
26 } 26 }
27 async updateReleaseId(value: number) { 27 async updateNightlyReleaseId(value: number) {
28 await this.globalState.update("releaseId", value); 28 await this.globalState.update("releaseId", value);
29 } 29 }
30 async removeReleaseId() { 30 async removeNightlyReleaseId() {
31 await this.globalState.update("releaseId", undefined); 31 await this.globalState.update("releaseId", undefined);
32 } 32 }
33 33