From d38f759c631039d11cb490692b5e07b00324ff10 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Wed, 23 Sep 2020 08:24:35 -0700 Subject: Use closure in trailing position and strongly type header map --- editors/code/src/main.ts | 37 ++++++++++++++++++++----------------- editors/code/src/net.ts | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'editors') diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 72c545b3c..0ee5280cc 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -177,9 +177,9 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi if (!shouldCheckForNewNightly) return; } - const release = await performDownloadWithRetryDialog(async () => { + const release = await performDownloadWithRetryDialog(state, async () => { return await fetchRelease("nightly", state.githubToken); - }, state).catch((e) => { + }).catch((e) => { log.error(e); if (state.releaseId === undefined) { // Show error only for the initial download vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); @@ -199,7 +199,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); - await performDownloadWithRetryDialog(async () => { + await performDownloadWithRetryDialog(state, async () => { // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. await fs.unlink(dest).catch(err => { if (err.code !== "ENOENT") throw err; @@ -210,7 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi dest, progressTitle: "Downloading rust-analyzer extension", }); - }, state); + }); await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); await fs.unlink(dest); @@ -323,13 +323,13 @@ async function getServer(config: Config, state: PersistentState): Promise { + const release = await performDownloadWithRetryDialog(state, async () => { return await fetchRelease(releaseTag, state.githubToken); - }, state); + }); const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); - await performDownloadWithRetryDialog(async () => { + await performDownloadWithRetryDialog(state, async () => { // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. await fs.unlink(dest).catch(err => { if (err.code !== "ENOENT") throw err; @@ -342,7 +342,7 @@ async function getServer(config: Config, state: PersistentState): Promise true).catch(_ => false)) { @@ -353,7 +353,7 @@ async function getServer(config: Config, state: PersistentState): Promise(downloadFunc: () => Promise, state: PersistentState): Promise { +async function performDownloadWithRetryDialog(state: PersistentState, downloadFunc: () => Promise): Promise { while (true) { try { return await downloadFunc(); @@ -392,13 +392,16 @@ async function queryForGithubToken(state: PersistentState): Promise { }; const newToken = await vscode.window.showInputBox(githubTokenOptions); - if (newToken !== undefined) { - if (newToken === "") { - log.info("Clearing github token"); - await state.updateGithubToken(undefined); - } else { - log.info("Storing new github token"); - await state.updateGithubToken(newToken); - } + if (newToken === undefined) { + // The user aborted the dialog => Do not update the stored token + return; + } + + if (newToken === "") { + log.info("Clearing github token"); + await state.updateGithubToken(undefined); + } else { + log.info("Storing new github token"); + await state.updateGithubToken(newToken); } } diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index d6194b63e..cfbe1fd48 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -28,7 +28,7 @@ export async function fetchRelease( log.debug("Issuing request for released artifacts metadata to", requestUrl); - var headers: any = { Accept: "application/vnd.github.v3+json" }; + const headers: Record = { Accept: "application/vnd.github.v3+json" }; if (githubToken != null) { headers.Authorization = "token " + githubToken; } -- cgit v1.2.3