mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
Use closure in trailing position and strongly type header map
This commit is contained in:
parent
87933e15ce
commit
d38f759c63
@ -177,9 +177,9 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||||||
if (!shouldCheckForNewNightly) return;
|
if (!shouldCheckForNewNightly) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const release = await performDownloadWithRetryDialog(async () => {
|
const release = await performDownloadWithRetryDialog(state, async () => {
|
||||||
return await fetchRelease("nightly", state.githubToken);
|
return await fetchRelease("nightly", state.githubToken);
|
||||||
}, state).catch((e) => {
|
}).catch((e) => {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
if (state.releaseId === undefined) { // Show error only for the initial download
|
if (state.releaseId === undefined) { // Show error only for the initial download
|
||||||
vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
|
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");
|
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.
|
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
|
||||||
await fs.unlink(dest).catch(err => {
|
await fs.unlink(dest).catch(err => {
|
||||||
if (err.code !== "ENOENT") throw err;
|
if (err.code !== "ENOENT") throw err;
|
||||||
@ -210,7 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
|||||||
dest,
|
dest,
|
||||||
progressTitle: "Downloading rust-analyzer extension",
|
progressTitle: "Downloading rust-analyzer extension",
|
||||||
});
|
});
|
||||||
}, state);
|
});
|
||||||
|
|
||||||
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
|
||||||
await fs.unlink(dest);
|
await fs.unlink(dest);
|
||||||
@ -323,13 +323,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
|||||||
}
|
}
|
||||||
|
|
||||||
const releaseTag = config.package.releaseTag;
|
const releaseTag = config.package.releaseTag;
|
||||||
const release = await performDownloadWithRetryDialog(async () => {
|
const release = await performDownloadWithRetryDialog(state, async () => {
|
||||||
return await fetchRelease(releaseTag, state.githubToken);
|
return await fetchRelease(releaseTag, state.githubToken);
|
||||||
}, state);
|
});
|
||||||
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
|
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
|
||||||
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
|
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.
|
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
|
||||||
await fs.unlink(dest).catch(err => {
|
await fs.unlink(dest).catch(err => {
|
||||||
if (err.code !== "ENOENT") throw err;
|
if (err.code !== "ENOENT") throw err;
|
||||||
@ -342,7 +342,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
|||||||
gunzip: true,
|
gunzip: true,
|
||||||
mode: 0o755
|
mode: 0o755
|
||||||
});
|
});
|
||||||
}, state);
|
});
|
||||||
|
|
||||||
// Patching executable if that's NixOS.
|
// Patching executable if that's NixOS.
|
||||||
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
|
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
|
||||||
@ -353,7 +353,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function performDownloadWithRetryDialog<T>(downloadFunc: () => Promise<T>, state: PersistentState): Promise<T> {
|
async function performDownloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
return await downloadFunc();
|
return await downloadFunc();
|
||||||
@ -392,13 +392,16 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const newToken = await vscode.window.showInputBox(githubTokenOptions);
|
const newToken = await vscode.window.showInputBox(githubTokenOptions);
|
||||||
if (newToken !== undefined) {
|
if (newToken === undefined) {
|
||||||
if (newToken === "") {
|
// The user aborted the dialog => Do not update the stored token
|
||||||
log.info("Clearing github token");
|
return;
|
||||||
await state.updateGithubToken(undefined);
|
}
|
||||||
} else {
|
|
||||||
log.info("Storing new github token");
|
if (newToken === "") {
|
||||||
await state.updateGithubToken(newToken);
|
log.info("Clearing github token");
|
||||||
}
|
await state.updateGithubToken(undefined);
|
||||||
|
} else {
|
||||||
|
log.info("Storing new github token");
|
||||||
|
await state.updateGithubToken(newToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export async function fetchRelease(
|
|||||||
|
|
||||||
log.debug("Issuing request for released artifacts metadata to", requestUrl);
|
log.debug("Issuing request for released artifacts metadata to", requestUrl);
|
||||||
|
|
||||||
var headers: any = { Accept: "application/vnd.github.v3+json" };
|
const headers: Record<string, string> = { Accept: "application/vnd.github.v3+json" };
|
||||||
if (githubToken != null) {
|
if (githubToken != null) {
|
||||||
headers.Authorization = "token " + githubToken;
|
headers.Authorization = "token " + githubToken;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user