diff options
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index bd99d696a..8c1610570 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -173,7 +173,9 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
173 | if (!shouldCheckForNewNightly) return; | 173 | if (!shouldCheckForNewNightly) return; |
174 | } | 174 | } |
175 | 175 | ||
176 | const release = await fetchRelease("nightly").catch((e) => { | 176 | const release = await performDownloadWithRetryDialog(async () => { |
177 | return await fetchRelease("nightly", state.githubToken); | ||
178 | }, state).catch((e) => { | ||
177 | log.error(e); | 179 | log.error(e); |
178 | if (state.releaseId === undefined) { // Show error only for the initial download | 180 | if (state.releaseId === undefined) { // Show error only for the initial download |
179 | vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); | 181 | vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); |
@@ -308,7 +310,10 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
308 | if (userResponse !== "Download now") return dest; | 310 | if (userResponse !== "Download now") return dest; |
309 | } | 311 | } |
310 | 312 | ||
311 | const release = await fetchRelease(config.package.releaseTag); | 313 | const releaseTag = config.package.releaseTag; |
314 | const release = await performDownloadWithRetryDialog(async () => { | ||
315 | return await fetchRelease(releaseTag, state.githubToken); | ||
316 | }, state); | ||
312 | const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); | 317 | const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); |
313 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); | 318 | assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); |
314 | 319 | ||
@@ -333,3 +338,49 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
333 | await state.updateServerVersion(config.package.version); | 338 | await state.updateServerVersion(config.package.version); |
334 | return dest; | 339 | return dest; |
335 | } | 340 | } |
341 | |||
342 | async function performDownloadWithRetryDialog<T>(downloadFunc: () => Promise<T>, state: PersistentState): Promise<T> { | ||
343 | while (true) { | ||
344 | try { | ||
345 | return await downloadFunc(); | ||
346 | } catch (e) { | ||
347 | let selected = await vscode.window.showErrorMessage("Failed perform download: " + e.message, {}, { | ||
348 | title: "Update Github Auth Token", | ||
349 | updateToken: true, | ||
350 | }, { | ||
351 | title: "Retry download", | ||
352 | retry: true, | ||
353 | }, { | ||
354 | title: "Dismiss", | ||
355 | }); | ||
356 | |||
357 | if (selected?.updateToken) { | ||
358 | await queryForGithubToken(state); | ||
359 | continue; | ||
360 | } else if (selected?.retry) { | ||
361 | continue; | ||
362 | } | ||
363 | throw e; | ||
364 | }; | ||
365 | } | ||
366 | |||
367 | } | ||
368 | |||
369 | async function queryForGithubToken(state: PersistentState): Promise<void> { | ||
370 | const githubTokenOptions: vscode.InputBoxOptions = { | ||
371 | value: state.githubToken, | ||
372 | password: true, | ||
373 | prompt: ` | ||
374 | This dialog allows to store a Github authorization token. | ||
375 | The usage of an authorization token allows will increase the rate | ||
376 | limit on the use of Github APIs and can thereby prevent getting | ||
377 | throttled. | ||
378 | Auth tokens can be obtained at https://github.com/settings/tokens`, | ||
379 | }; | ||
380 | |||
381 | const newToken = await vscode.window.showInputBox(githubTokenOptions); | ||
382 | if (newToken) { | ||
383 | log.info("Storing new github token"); | ||
384 | await state.updateGithubToken(newToken); | ||
385 | } | ||
386 | } \ No newline at end of file | ||