aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-23 11:57:04 +0100
committerKirill Bulatov <[email protected]>2021-05-23 11:57:04 +0100
commitdaedcc2b77187486fde13a2813809b06b2385ac0 (patch)
tree60b2b267baadbc1be09ac338611c68de59fd0174
parent223dbd2187e5b966d192dac9745d47831dccb9b3 (diff)
More style fixes
-rw-r--r--editors/code/src/config.ts6
-rw-r--r--editors/code/src/main.ts29
2 files changed, 19 insertions, 16 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index c9249768d..fbb7a556a 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -4,7 +4,7 @@ import { log } from "./util";
4 4
5export type UpdatesChannel = "stable" | "nightly"; 5export type UpdatesChannel = "stable" | "nightly";
6 6
7export const NIGHTLY_TAG = "nightly"; 7const NIGHTLY_TAG = "nightly";
8 8
9export type RunnableEnvCfg = undefined | Record<string, string> | { mask?: string; env: Record<string, string> }[]; 9export type RunnableEnvCfg = undefined | Record<string, string> | { mask?: string; env: Record<string, string> }[];
10 10
@@ -170,4 +170,8 @@ export class Config {
170 gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"), 170 gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),
171 }; 171 };
172 } 172 }
173
174 get currentExtensionIsNightly() {
175 return this.package.releaseTag === NIGHTLY_TAG;
176 }
173} 177}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a6c1c0906..aaedc2431 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -6,7 +6,7 @@ import { promises as fs, PathLike } from "fs";
6import * as commands from './commands'; 6import * as commands from './commands';
7import { activateInlayHints } from './inlay_hints'; 7import { activateInlayHints } from './inlay_hints';
8import { Ctx } from './ctx'; 8import { Ctx } from './ctx';
9import { Config, NIGHTLY_TAG } from './config'; 9import { Config } from './config';
10import { log, assert, isValidExecutable } from './util'; 10import { log, assert, isValidExecutable } from './util';
11import { PersistentState } from './persistent_state'; 11import { PersistentState } from './persistent_state';
12import { fetchRelease, download } from './net'; 12import { fetchRelease, download } from './net';
@@ -156,7 +156,7 @@ 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.currentExtensionIsNightly) {
160 await state.updateNightlyReleaseId(undefined); 160 await state.updateNightlyReleaseId(undefined);
161 } 161 }
162 await bootstrapExtension(config, state); 162 await bootstrapExtension(config, state);
@@ -166,9 +166,8 @@ 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;
170 if (config.channel === "stable") { 169 if (config.channel === "stable") {
171 if (currentExtensionIsNightly) { 170 if (config.currentExtensionIsNightly) {
172 void vscode.window.showWarningMessage( 171 void vscode.window.showWarningMessage(
173 `You are running a nightly version of rust-analyzer extension. ` + 172 `You are running a nightly version of rust-analyzer extension. ` +
174 `To switch to stable, uninstall the extension and re-install it from the marketplace` 173 `To switch to stable, uninstall the extension and re-install it from the marketplace`
@@ -179,34 +178,34 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
179 if (serverPath(config)) return; 178 if (serverPath(config)) return;
180 179
181 const now = Date.now(); 180 const now = Date.now();
182 const isInitialDownload = state.nightlyReleaseId === undefined; 181 const isInitialNightlyDownload = state.nightlyReleaseId === undefined;
183 if (currentExtensionIsNightly) { 182 if (config.currentExtensionIsNightly) {
184 // Check if we should poll github api for the new nightly version 183 // Check if we should poll github api for the new nightly version
185 // if we haven't done it during the past hour 184 // if we haven't done it during the past hour
186 const lastCheck = state.lastCheck; 185 const lastCheck = state.lastCheck;
187 186
188 const anHour = 60 * 60 * 1000; 187 const anHour = 60 * 60 * 1000;
189 const shouldCheckForNewNightly = isInitialDownload || (now - (lastCheck ?? 0)) > anHour; 188 const shouldCheckForNewNightly = isInitialNightlyDownload || (now - (lastCheck ?? 0)) > anHour;
190 189
191 if (!shouldCheckForNewNightly) return; 190 if (!shouldCheckForNewNightly) return;
192 } 191 }
193 192
194 const release = await downloadWithRetryDialog(state, async () => { 193 const latestNightlyRelease = await downloadWithRetryDialog(state, async () => {
195 return await fetchRelease("nightly", state.githubToken, config.httpProxy); 194 return await fetchRelease("nightly", state.githubToken, config.httpProxy);
196 }).catch(async (e) => { 195 }).catch(async (e) => {
197 log.error(e); 196 log.error(e);
198 if (isInitialDownload) { 197 if (isInitialNightlyDownload) {
199 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`); 198 await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly: ${e}`);
200 } 199 }
201 return; 200 return;
202 }); 201 });
203 if (release === undefined) { 202 if (latestNightlyRelease === undefined) {
204 if (isInitialDownload) { 203 if (isInitialNightlyDownload) {
205 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned"); 204 await vscode.window.showErrorMessage("Failed to download rust-analyzer nightly: empty release contents returned");
206 } 205 }
207 return; 206 return;
208 } 207 }
209 if (currentExtensionIsNightly && release.id === state.nightlyReleaseId) return; 208 if (config.currentExtensionIsNightly && latestNightlyRelease.id === state.nightlyReleaseId) return;
210 209
211 const userResponse = await vscode.window.showInformationMessage( 210 const userResponse = await vscode.window.showInformationMessage(
212 "New version of rust-analyzer (nightly) is available (requires reload).", 211 "New version of rust-analyzer (nightly) is available (requires reload).",
@@ -214,8 +213,8 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
214 ); 213 );
215 if (userResponse !== "Update") return; 214 if (userResponse !== "Update") return;
216 215
217 const artifact = release.assets.find(artifact => artifact.name === "rust-analyzer.vsix"); 216 const artifact = latestNightlyRelease.assets.find(artifact => artifact.name === "rust-analyzer.vsix");
218 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 217 assert(!!artifact, `Bad release: ${JSON.stringify(latestNightlyRelease)}`);
219 218
220 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); 219 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
221 220
@@ -231,7 +230,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
231 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); 230 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
232 await fs.unlink(dest); 231 await fs.unlink(dest);
233 232
234 await state.updateNightlyReleaseId(release.id); 233 await state.updateNightlyReleaseId(latestNightlyRelease.id);
235 await state.updateLastCheck(now); 234 await state.updateLastCheck(now);
236 await vscode.commands.executeCommand("workbench.action.reloadWindow"); 235 await vscode.commands.executeCommand("workbench.action.reloadWindow");
237} 236}