Skip to content

Commit d38f759

Browse files
committed
Use closure in trailing position and strongly type header map
1 parent 87933e1 commit d38f759

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

editors/code/src/main.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
177177
if (!shouldCheckForNewNightly) return;
178178
}
179179

180-
const release = await performDownloadWithRetryDialog(async () => {
180+
const release = await performDownloadWithRetryDialog(state, async () => {
181181
return await fetchRelease("nightly", state.githubToken);
182-
}, state).catch((e) => {
182+
}).catch((e) => {
183183
log.error(e);
184184
if (state.releaseId === undefined) { // Show error only for the initial download
185185
vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
@@ -199,7 +199,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
199199

200200
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
201201

202-
await performDownloadWithRetryDialog(async () => {
202+
await performDownloadWithRetryDialog(state, async () => {
203203
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
204204
await fs.unlink(dest).catch(err => {
205205
if (err.code !== "ENOENT") throw err;
@@ -210,7 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
210210
dest,
211211
progressTitle: "Downloading rust-analyzer extension",
212212
});
213-
}, state);
213+
});
214214

215215
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
216216
await fs.unlink(dest);
@@ -323,13 +323,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
323323
}
324324

325325
const releaseTag = config.package.releaseTag;
326-
const release = await performDownloadWithRetryDialog(async () => {
326+
const release = await performDownloadWithRetryDialog(state, async () => {
327327
return await fetchRelease(releaseTag, state.githubToken);
328-
}, state);
328+
});
329329
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
330330
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
331331

332-
await performDownloadWithRetryDialog(async () => {
332+
await performDownloadWithRetryDialog(state, async () => {
333333
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
334334
await fs.unlink(dest).catch(err => {
335335
if (err.code !== "ENOENT") throw err;
@@ -342,7 +342,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
342342
gunzip: true,
343343
mode: 0o755
344344
});
345-
}, state);
345+
});
346346

347347
// Patching executable if that's NixOS.
348348
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
@@ -353,7 +353,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
353353
return dest;
354354
}
355355

356-
async function performDownloadWithRetryDialog<T>(downloadFunc: () => Promise<T>, state: PersistentState): Promise<T> {
356+
async function performDownloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
357357
while (true) {
358358
try {
359359
return await downloadFunc();
@@ -392,13 +392,16 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
392392
};
393393

394394
const newToken = await vscode.window.showInputBox(githubTokenOptions);
395-
if (newToken !== undefined) {
396-
if (newToken === "") {
397-
log.info("Clearing github token");
398-
await state.updateGithubToken(undefined);
399-
} else {
400-
log.info("Storing new github token");
401-
await state.updateGithubToken(newToken);
402-
}
395+
if (newToken === undefined) {
396+
// The user aborted the dialog => Do not update the stored token
397+
return;
398+
}
399+
400+
if (newToken === "") {
401+
log.info("Clearing github token");
402+
await state.updateGithubToken(undefined);
403+
} else {
404+
log.info("Storing new github token");
405+
await state.updateGithubToken(newToken);
403406
}
404407
}

editors/code/src/net.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function fetchRelease(
2828

2929
log.debug("Issuing request for released artifacts metadata to", requestUrl);
3030

31-
var headers: any = { Accept: "application/vnd.github.v3+json" };
31+
const headers: Record<string, string> = { Accept: "application/vnd.github.v3+json" };
3232
if (githubToken != null) {
3333
headers.Authorization = "token " + githubToken;
3434
}

0 commit comments

Comments
 (0)