@@ -5,9 +5,8 @@ import * as commands from './commands';
5
5
import { activateInlayHints } from './inlay_hints' ;
6
6
import { Ctx } from './ctx' ;
7
7
import { Config } from './config' ;
8
- import { log , assert , isValidExecutable , isRustDocument } from './util' ;
8
+ import { log , isValidExecutable , isRustDocument } from './util' ;
9
9
import { PersistentState } from './persistent_state' ;
10
- import { fetchRelease , download } from './net' ;
11
10
import { activateTaskProvider } from './tasks' ;
12
11
import { setContextValue } from './util' ;
13
12
import { exec , spawnSync } from 'child_process' ;
@@ -111,10 +110,6 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
111
110
await activate ( context ) . catch ( log . error ) ;
112
111
} ) ;
113
112
114
- ctx . registerCommand ( 'updateGithubToken' , ctx => async ( ) => {
115
- await queryForGithubToken ( new PersistentState ( ctx . globalState ) ) ;
116
- } ) ;
117
-
118
113
ctx . registerCommand ( 'analyzerStatus' , commands . analyzerStatus ) ;
119
114
ctx . registerCommand ( 'memoryUsage' , commands . memoryUsage ) ;
120
115
ctx . registerCommand ( 'shuffleCrateGraph' , commands . shuffleCrateGraph ) ;
@@ -163,95 +158,10 @@ export async function deactivate() {
163
158
164
159
async function bootstrap ( config : Config , state : PersistentState ) : Promise < string > {
165
160
await vscode . workspace . fs . createDirectory ( config . globalStorageUri ) . then ( ) ;
166
-
167
- if ( ! config . currentExtensionIsNightly ) {
168
- await state . updateNightlyReleaseId ( undefined ) ;
169
- }
170
- await bootstrapExtension ( config , state ) ;
171
161
const path = await bootstrapServer ( config , state ) ;
172
162
return path ;
173
163
}
174
164
175
- async function bootstrapExtension ( config : Config , state : PersistentState ) : Promise < void > {
176
- if ( config . package . releaseTag === null ) return ;
177
- if ( config . channel === "stable" ) {
178
- if ( config . currentExtensionIsNightly ) {
179
- void vscode . window . showWarningMessage (
180
- `You are running a nightly version of rust-analyzer extension. ` +
181
- `To switch to stable, uninstall the extension and re-install it from the marketplace`
182
- ) ;
183
- }
184
- return ;
185
- } ;
186
- if ( serverPath ( config ) ) return ;
187
-
188
- const now = Date . now ( ) ;
189
- const isInitialNightlyDownload = state . nightlyReleaseId === undefined ;
190
- if ( config . currentExtensionIsNightly ) {
191
- // Check if we should poll github api for the new nightly version
192
- // if we haven't done it during the past hour
193
- const lastCheck = state . lastCheck ;
194
-
195
- const anHour = 60 * 60 * 1000 ;
196
- const shouldCheckForNewNightly = isInitialNightlyDownload || ( now - ( lastCheck ?? 0 ) ) > anHour ;
197
-
198
- if ( ! shouldCheckForNewNightly ) return ;
199
- }
200
-
201
- const latestNightlyRelease = await downloadWithRetryDialog ( state , async ( ) => {
202
- return await fetchRelease ( "nightly" , state . githubToken , config . proxySettings ) ;
203
- } ) . catch ( async ( e ) => {
204
- log . error ( e ) ;
205
- if ( isInitialNightlyDownload ) {
206
- await vscode . window . showErrorMessage ( `Failed to download rust-analyzer nightly: ${ e } ` ) ;
207
- }
208
- return ;
209
- } ) ;
210
- if ( latestNightlyRelease === undefined ) {
211
- if ( isInitialNightlyDownload ) {
212
- await vscode . window . showErrorMessage ( "Failed to download rust-analyzer nightly: empty release contents returned" ) ;
213
- }
214
- return ;
215
- }
216
- if ( config . currentExtensionIsNightly && latestNightlyRelease . id === state . nightlyReleaseId ) return ;
217
-
218
- const userResponse = await vscode . window . showInformationMessage (
219
- "New version of rust-analyzer (nightly) is available (requires reload)." ,
220
- "Update"
221
- ) ;
222
- if ( userResponse !== "Update" ) return ;
223
-
224
- let arch = process . arch ;
225
- if ( arch === "ia32" ) {
226
- arch = "x64" ;
227
- }
228
- let platform = process . platform as string ;
229
- if ( platform === "linux" && isMusl ( ) ) {
230
- platform = "alpine" ;
231
- }
232
- const artifactName = `rust-analyzer-${ platform } -${ arch } .vsix` ;
233
-
234
- const artifact = latestNightlyRelease . assets . find ( artifact => artifact . name === artifactName ) ;
235
- assert ( ! ! artifact , `Bad release: ${ JSON . stringify ( latestNightlyRelease ) } ` ) ;
236
- const dest = vscode . Uri . joinPath ( config . globalStorageUri , "rust-analyzer.vsix" ) ;
237
-
238
- await downloadWithRetryDialog ( state , async ( ) => {
239
- await download ( {
240
- url : artifact . browser_download_url ,
241
- dest,
242
- progressTitle : "Downloading rust-analyzer extension" ,
243
- proxySettings : config . proxySettings ,
244
- } ) ;
245
- } ) ;
246
-
247
- await vscode . commands . executeCommand ( "workbench.extensions.installExtension" , dest ) ;
248
- await vscode . workspace . fs . delete ( dest ) ;
249
-
250
- await state . updateNightlyReleaseId ( latestNightlyRelease . id ) ;
251
- await state . updateLastCheck ( now ) ;
252
- await vscode . commands . executeCommand ( "workbench.action.reloadWindow" ) ;
253
- }
254
-
255
165
async function bootstrapServer ( config : Config , state : PersistentState ) : Promise < string > {
256
166
const path = await getServer ( config , state ) ;
257
167
if ( ! path ) {
@@ -356,56 +266,16 @@ async function getServer(config: Config, state: PersistentState): Promise<string
356
266
const dest = vscode . Uri . joinPath ( config . globalStorageUri , `rust-analyzer-${ platform } ${ ext } ` ) ;
357
267
const bundled = vscode . Uri . joinPath ( config . installUri , "server" , `rust-analyzer${ ext } ` ) ;
358
268
const bundledExists = await vscode . workspace . fs . stat ( bundled ) . then ( ( ) => true , ( ) => false ) ;
359
- let exists = await vscode . workspace . fs . stat ( dest ) . then ( ( ) => true , ( ) => false ) ;
269
+ const exists = await vscode . workspace . fs . stat ( dest ) . then ( ( ) => true , ( ) => false ) ;
360
270
if ( bundledExists ) {
361
- await state . updateServerVersion ( config . package . version ) ;
362
271
if ( ! await isNixOs ( ) ) {
363
272
return bundled . fsPath ;
364
273
}
365
274
if ( ! exists ) {
366
275
await vscode . workspace . fs . copy ( bundled , dest ) ;
367
276
await patchelf ( dest ) ;
368
- exists = true ;
369
277
}
370
278
}
371
- if ( ! exists ) {
372
- await state . updateServerVersion ( undefined ) ;
373
- }
374
-
375
- if ( state . serverVersion === config . package . version ) return dest . fsPath ;
376
-
377
- if ( config . askBeforeDownload ) {
378
- const userResponse = await vscode . window . showInformationMessage (
379
- `Language server version ${ config . package . version } for rust-analyzer is not installed.` ,
380
- "Download now"
381
- ) ;
382
- if ( userResponse !== "Download now" ) return dest . fsPath ;
383
- }
384
-
385
- const releaseTag = config . package . releaseTag ;
386
- const release = await downloadWithRetryDialog ( state , async ( ) => {
387
- return await fetchRelease ( releaseTag , state . githubToken , config . proxySettings ) ;
388
- } ) ;
389
- const artifact = release . assets . find ( artifact => artifact . name === `rust-analyzer-${ platform } .gz` ) ;
390
- assert ( ! ! artifact , `Bad release: ${ JSON . stringify ( release ) } ` ) ;
391
-
392
- await downloadWithRetryDialog ( state , async ( ) => {
393
- await download ( {
394
- url : artifact . browser_download_url ,
395
- dest,
396
- progressTitle : "Downloading rust-analyzer server" ,
397
- gunzip : true ,
398
- mode : 0o755 ,
399
- proxySettings : config . proxySettings ,
400
- } ) ;
401
- } ) ;
402
-
403
- // Patching executable if that's NixOS.
404
- if ( await isNixOs ( ) ) {
405
- await patchelf ( dest ) ;
406
- }
407
-
408
- await state . updateServerVersion ( config . package . version ) ;
409
279
return dest . fsPath ;
410
280
}
411
281
@@ -429,59 +299,6 @@ function isMusl(): boolean {
429
299
return res . stderr != null && res . stderr . indexOf ( "musl libc" ) >= 0 ;
430
300
}
431
301
432
- async function downloadWithRetryDialog < T > ( state : PersistentState , downloadFunc : ( ) => Promise < T > ) : Promise < T > {
433
- while ( true ) {
434
- try {
435
- return await downloadFunc ( ) ;
436
- } catch ( e ) {
437
- const selected = await vscode . window . showErrorMessage ( "Failed to download: " + e . message , { } , {
438
- title : "Update Github Auth Token" ,
439
- updateToken : true ,
440
- } , {
441
- title : "Retry download" ,
442
- retry : true ,
443
- } , {
444
- title : "Dismiss" ,
445
- } ) ;
446
-
447
- if ( selected ?. updateToken ) {
448
- await queryForGithubToken ( state ) ;
449
- continue ;
450
- } else if ( selected ?. retry ) {
451
- continue ;
452
- }
453
- throw e ;
454
- } ;
455
- }
456
- }
457
-
458
- async function queryForGithubToken ( state : PersistentState ) : Promise < void > {
459
- const githubTokenOptions : vscode . InputBoxOptions = {
460
- value : state . githubToken ,
461
- password : true ,
462
- prompt : `
463
- This dialog allows to store a Github authorization token.
464
- The usage of an authorization token will increase the rate
465
- limit on the use of Github APIs and can thereby prevent getting
466
- throttled.
467
- Auth tokens can be created at https://github.com/settings/tokens` ,
468
- } ;
469
-
470
- const newToken = await vscode . window . showInputBox ( githubTokenOptions ) ;
471
- if ( newToken === undefined ) {
472
- // The user aborted the dialog => Do not update the stored token
473
- return ;
474
- }
475
-
476
- if ( newToken === "" ) {
477
- log . info ( "Clearing github token" ) ;
478
- await state . updateGithubToken ( undefined ) ;
479
- } else {
480
- log . info ( "Storing new github token" ) ;
481
- await state . updateGithubToken ( newToken ) ;
482
- }
483
- }
484
-
485
302
function warnAboutExtensionConflicts ( ) {
486
303
const conflicting = [
487
304
[ "rust-analyzer" , "matklad.rust-analyzer" ] ,
0 commit comments