aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/main.ts37
-rw-r--r--editors/code/src/net.ts2
2 files changed, 21 insertions, 18 deletions
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
177 if (!shouldCheckForNewNightly) return; 177 if (!shouldCheckForNewNightly) return;
178 } 178 }
179 179
180 const release = await performDownloadWithRetryDialog(async () => { 180 const release = await performDownloadWithRetryDialog(state, async () => {
181 return await fetchRelease("nightly", state.githubToken); 181 return await fetchRelease("nightly", state.githubToken);
182 }, state).catch((e) => { 182 }).catch((e) => {
183 log.error(e); 183 log.error(e);
184 if (state.releaseId === undefined) { // Show error only for the initial download 184 if (state.releaseId === undefined) { // Show error only for the initial download
185 vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`); 185 vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
@@ -199,7 +199,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
199 199
200 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); 200 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
201 201
202 await performDownloadWithRetryDialog(async () => { 202 await performDownloadWithRetryDialog(state, async () => {
203 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. 203 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
204 await fs.unlink(dest).catch(err => { 204 await fs.unlink(dest).catch(err => {
205 if (err.code !== "ENOENT") throw err; 205 if (err.code !== "ENOENT") throw err;
@@ -210,7 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
210 dest, 210 dest,
211 progressTitle: "Downloading rust-analyzer extension", 211 progressTitle: "Downloading rust-analyzer extension",
212 }); 212 });
213 }, state); 213 });
214 214
215 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); 215 await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
216 await fs.unlink(dest); 216 await fs.unlink(dest);
@@ -323,13 +323,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
323 } 323 }
324 324
325 const releaseTag = config.package.releaseTag; 325 const releaseTag = config.package.releaseTag;
326 const release = await performDownloadWithRetryDialog(async () => { 326 const release = await performDownloadWithRetryDialog(state, async () => {
327 return await fetchRelease(releaseTag, state.githubToken); 327 return await fetchRelease(releaseTag, state.githubToken);
328 }, state); 328 });
329 const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); 329 const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
330 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 330 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
331 331
332 await performDownloadWithRetryDialog(async () => { 332 await performDownloadWithRetryDialog(state, async () => {
333 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. 333 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
334 await fs.unlink(dest).catch(err => { 334 await fs.unlink(dest).catch(err => {
335 if (err.code !== "ENOENT") throw err; 335 if (err.code !== "ENOENT") throw err;
@@ -342,7 +342,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
342 gunzip: true, 342 gunzip: true,
343 mode: 0o755 343 mode: 0o755
344 }); 344 });
345 }, state); 345 });
346 346
347 // Patching executable if that's NixOS. 347 // Patching executable if that's NixOS.
348 if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) { 348 if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
@@ -353,7 +353,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
353 return dest; 353 return dest;
354} 354}
355 355
356async function performDownloadWithRetryDialog<T>(downloadFunc: () => Promise<T>, state: PersistentState): Promise<T> { 356async function performDownloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
357 while (true) { 357 while (true) {
358 try { 358 try {
359 return await downloadFunc(); 359 return await downloadFunc();
@@ -392,13 +392,16 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
392 }; 392 };
393 393
394 const newToken = await vscode.window.showInputBox(githubTokenOptions); 394 const newToken = await vscode.window.showInputBox(githubTokenOptions);
395 if (newToken !== undefined) { 395 if (newToken === undefined) {
396 if (newToken === "") { 396 // The user aborted the dialog => Do not update the stored token
397 log.info("Clearing github token"); 397 return;
398 await state.updateGithubToken(undefined); 398 }
399 } else { 399
400 log.info("Storing new github token"); 400 if (newToken === "") {
401 await state.updateGithubToken(newToken); 401 log.info("Clearing github token");
402 } 402 await state.updateGithubToken(undefined);
403 } else {
404 log.info("Storing new github token");
405 await state.updateGithubToken(newToken);
403 } 406 }
404} 407}
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(
28 28
29 log.debug("Issuing request for released artifacts metadata to", requestUrl); 29 log.debug("Issuing request for released artifacts metadata to", requestUrl);
30 30
31 var headers: any = { Accept: "application/vnd.github.v3+json" }; 31 const headers: Record<string, string> = { Accept: "application/vnd.github.v3+json" };
32 if (githubToken != null) { 32 if (githubToken != null) {
33 headers.Authorization = "token " + githubToken; 33 headers.Authorization = "token " + githubToken;
34 } 34 }