aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-23 11:17:09 +0100
committerKirill Bulatov <[email protected]>2021-05-23 11:43:06 +0100
commit223dbd2187e5b966d192dac9745d47831dccb9b3 (patch)
tree50669f643998b7864b904d75b72a719dd7686a02 /editors
parent95c51d8f1df1efdb2e98b7717544a6db8cad14e7 (diff)
Style fix
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/main.ts18
-rw-r--r--editors/code/src/persistent_state.ts5
2 files changed, 11 insertions, 12 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 6ed8b6146..a6c1c0906 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -156,8 +156,8 @@ export async function deactivate() {
156async function bootstrap(config: Config, state: PersistentState): Promise<string> { 156async 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.removeNightlyReleaseId(); 160 await state.updateNightlyReleaseId(undefined);
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);
@@ -166,8 +166,9 @@ async function bootstrap(config: Config, state: PersistentState): Promise<string
166 166
167async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> { 167async function bootstrapExtension(config: Config, state: PersistentState): Promise<void> {
168 if (config.package.releaseTag === null) return; 168 if (config.package.releaseTag === null) return;
169 const currentExtensionIsNightly = config.package.releaseTag === NIGHTLY_TAG;
169 if (config.channel === "stable") { 170 if (config.channel === "stable") {
170 if (config.package.releaseTag === NIGHTLY_TAG) { 171 if (currentExtensionIsNightly) {
171 void vscode.window.showWarningMessage( 172 void vscode.window.showWarningMessage(
172 `You are running a nightly version of rust-analyzer extension. ` + 173 `You are running a nightly version of rust-analyzer extension. ` +
173 `To switch to stable, uninstall the extension and re-install it from the marketplace` 174 `To switch to stable, uninstall the extension and re-install it from the marketplace`
@@ -178,13 +179,14 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
178 if (serverPath(config)) return; 179 if (serverPath(config)) return;
179 180
180 const now = Date.now(); 181 const now = Date.now();
181 if (config.package.releaseTag === NIGHTLY_TAG) { 182 const isInitialDownload = state.nightlyReleaseId === undefined;
183 if (currentExtensionIsNightly) {
182 // Check if we should poll github api for the new nightly version 184 // Check if we should poll github api for the new nightly version
183 // if we haven't done it during the past hour 185 // if we haven't done it during the past hour
184 const lastCheck = state.lastCheck; 186 const lastCheck = state.lastCheck;
185 187
186 const anHour = 60 * 60 * 1000; 188 const anHour = 60 * 60 * 1000;
187 const shouldCheckForNewNightly = state.nightlyReleaseId === undefined || (now - (lastCheck ?? 0)) > anHour; 189 const shouldCheckForNewNightly = isInitialDownload || (now - (lastCheck ?? 0)) > anHour;
188 190
189 if (!shouldCheckForNewNightly) return; 191 if (!shouldCheckForNewNightly) return;
190 } 192 }
@@ -193,18 +195,18 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
193 return await fetchRelease("nightly", state.githubToken, config.httpProxy); 195 return await fetchRelease("nightly", state.githubToken, config.httpProxy);
194 }).catch(async (e) => { 196 }).catch(async (e) => {
195 log.error(e); 197 log.error(e);
196 if (state.nightlyReleaseId === undefined) { // Show error only for the initial download 198 if (isInitialDownload) {
197 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`); 199 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
198 } 200 }
199 return; 201 return;
200 }); 202 });
201 if (release === undefined) { 203 if (release === undefined) {
202 if (state.nightlyReleaseId === undefined) { // Show error only for the initial download 204 if (isInitialDownload) {
203 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned"); 205 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
204 } 206 }
205 return; 207 return;
206 } 208 }
207 if (config.package.releaseTag === NIGHTLY_TAG && release.id === state.nightlyReleaseId) return; 209 if (currentExtensionIsNightly && release.id === state.nightlyReleaseId) return;
208 210
209 const userResponse = await vscode.window.showInformationMessage( 211 const userResponse = await vscode.window.showInformationMessage(
210 "New version of rust-analyzer (nightly) is available (requires reload).", 212 "New version of rust-analyzer (nightly) is available (requires reload).",
diff --git a/editors/code/src/persistent_state.ts b/editors/code/src/persistent_state.ts
index c02eb2ca3..dd2aeecca 100644
--- a/editors/code/src/persistent_state.ts
+++ b/editors/code/src/persistent_state.ts
@@ -24,12 +24,9 @@ export class PersistentState {
24 get nightlyReleaseId(): number | undefined { 24 get nightlyReleaseId(): number | undefined {
25 return this.globalState.get("releaseId"); 25 return this.globalState.get("releaseId");
26 } 26 }
27 async updateNightlyReleaseId(value: number) { 27 async updateNightlyReleaseId(value: number | undefined) {
28 await this.globalState.update("releaseId", value); 28 await this.globalState.update("releaseId", value);
29 } 29 }
30 async removeNightlyReleaseId() {
31 await this.globalState.update("releaseId", undefined);
32 }
33 30
34 /** 31 /**
35 * Version of the extension that installed the server. 32 * Version of the extension that installed the server.