@@ -177,9 +177,9 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
177
177
if ( ! shouldCheckForNewNightly ) return ;
178
178
}
179
179
180
- const release = await performDownloadWithRetryDialog ( async ( ) => {
180
+ const release = await performDownloadWithRetryDialog ( state , async ( ) => {
181
181
return await fetchRelease ( "nightly" , state . githubToken ) ;
182
- } , state ) . catch ( ( e ) => {
182
+ } ) . catch ( ( e ) => {
183
183
log . error ( e ) ;
184
184
if ( state . releaseId === undefined ) { // Show error only for the initial download
185
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
200
const dest = path . join ( config . globalStoragePath , "rust-analyzer.vsix" ) ;
201
201
202
- await performDownloadWithRetryDialog ( async ( ) => {
202
+ await performDownloadWithRetryDialog ( state , async ( ) => {
203
203
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
204
204
await fs . unlink ( dest ) . catch ( err => {
205
205
if ( err . code !== "ENOENT" ) throw err ;
@@ -210,7 +210,7 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
210
210
dest,
211
211
progressTitle : "Downloading rust-analyzer extension" ,
212
212
} ) ;
213
- } , state ) ;
213
+ } ) ;
214
214
215
215
await vscode . commands . executeCommand ( "workbench.extensions.installExtension" , vscode . Uri . file ( dest ) ) ;
216
216
await fs . unlink ( dest ) ;
@@ -323,13 +323,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
323
323
}
324
324
325
325
const releaseTag = config . package . releaseTag ;
326
- const release = await performDownloadWithRetryDialog ( async ( ) => {
326
+ const release = await performDownloadWithRetryDialog ( state , async ( ) => {
327
327
return await fetchRelease ( releaseTag , state . githubToken ) ;
328
- } , state ) ;
328
+ } ) ;
329
329
const artifact = release . assets . find ( artifact => artifact . name === `rust-analyzer-${ platform } .gz` ) ;
330
330
assert ( ! ! artifact , `Bad release: ${ JSON . stringify ( release ) } ` ) ;
331
331
332
- await performDownloadWithRetryDialog ( async ( ) => {
332
+ await performDownloadWithRetryDialog ( state , async ( ) => {
333
333
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
334
334
await fs . unlink ( dest ) . catch ( err => {
335
335
if ( err . code !== "ENOENT" ) throw err ;
@@ -342,7 +342,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
342
342
gunzip : true ,
343
343
mode : 0o755
344
344
} ) ;
345
- } , state ) ;
345
+ } ) ;
346
346
347
347
// Patching executable if that's NixOS.
348
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
353
return dest ;
354
354
}
355
355
356
- async function performDownloadWithRetryDialog < T > ( downloadFunc : ( ) => Promise < T > , state : PersistentState ) : Promise < T > {
356
+ async function performDownloadWithRetryDialog < T > ( state : PersistentState , downloadFunc : ( ) => Promise < T > ) : Promise < T > {
357
357
while ( true ) {
358
358
try {
359
359
return await downloadFunc ( ) ;
@@ -392,13 +392,16 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
392
392
} ;
393
393
394
394
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 ) ;
403
406
}
404
407
}
0 commit comments