@@ -25,19 +25,19 @@ interface LastClientError {
25
25
export class Ctx {
26
26
readonly context : vscode . ExtensionContext ;
27
27
readonly config : Config ;
28
- readonly state : PersistentState ;
28
+ readonly state : PersistentState ;
29
29
readonly statusBar : vscode . StatusBarItem ;
30
-
30
+
31
31
// Stored initialization error. Cleared when reloaded.
32
32
lastClientError : LastClientError | null ;
33
33
client : lc . LanguageClient | null ;
34
- commands : { [ key :string ] : lc . Disposable } ;
34
+ commands : { [ key : string ] : lc . Disposable } ;
35
35
stopped : boolean ;
36
36
37
37
constructor ( context : vscode . ExtensionContext ) {
38
38
this . context = context ;
39
39
this . config = new Config ( context ) ;
40
- this . state = new PersistentState ( context . globalState ) ;
40
+ this . state = new PersistentState ( context . globalState ) ;
41
41
this . statusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
42
42
this . lastClientError = null ;
43
43
this . client = null ;
@@ -75,7 +75,7 @@ export class Ctx {
75
75
}
76
76
77
77
this . setupStatusBar ( ) ;
78
- }
78
+ }
79
79
80
80
command ( name : string , callback : ( ...args : any [ ] ) => any ) {
81
81
if ( ! this . commands [ name ] ) {
@@ -152,11 +152,11 @@ export class Ctx {
152
152
let [ code , out , err ] : [ number | null , string , string ] = await new Promise ( ( resolve , _ ) => {
153
153
let stdout = "" ;
154
154
let stderr = "" ;
155
-
155
+
156
156
cargoVersion . stdout . on ( "data" , ( chunk ) => {
157
157
stdout += chunk ;
158
158
} ) ;
159
-
159
+
160
160
cargoVersion . stderr . on ( "data" , ( chunk ) => {
161
161
stderr += chunk ;
162
162
} ) ;
@@ -211,7 +211,7 @@ export class Ctx {
211
211
child . stderr . setEncoding ( 'utf8' ) ;
212
212
child . stdout . setEncoding ( 'utf8' ) ;
213
213
let out = rl . createInterface ( child . stdout , child . stdin ) ;
214
-
214
+
215
215
this . statusBar . text = `rune: cargo build -p ${ name } ` ;
216
216
this . statusBar . tooltip = `rune: building package ${ name } , to use as rune language server` ;
217
217
this . statusBar . backgroundColor = new vscode . ThemeColor ( 'statusBarItem.warningBackground' ) ;
@@ -273,10 +273,10 @@ export class Ctx {
273
273
274
274
if ( explicitPath ) {
275
275
if ( explicitPath . startsWith ( "~/" ) ) {
276
- return { kind : "languageserver " , path : os . homedir ( ) + explicitPath . slice ( "~" . length ) } ;
276
+ return { kind : "cli " , path : os . homedir ( ) + explicitPath . slice ( "~" . length ) } ;
277
277
}
278
278
279
- return { kind : "languageserver " , path : explicitPath } ;
279
+ return { kind : "cli " , path : explicitPath } ;
280
280
}
281
281
282
282
const cargoPackage = this . config . serverCargoPackage ;
@@ -297,24 +297,25 @@ export class Ctx {
297
297
return null ;
298
298
}
299
299
300
- return { kind : "languageserver " , path } ;
300
+ return { kind : "cli " , path } ;
301
301
}
302
-
302
+
303
303
async downloadServer ( ) : Promise < string | null > {
304
- // unknown platform => no download available
305
- const platform = detectPlatform ( ) ;
304
+ const platformArch = detectPlatform ( ) ;
306
305
307
- if ( ! platform ) {
306
+ if ( ! platformArch ) {
308
307
return null ;
309
308
}
310
-
309
+
310
+ const [ platform , arch ] = platformArch ;
311
+
311
312
// platform specific binary name / path
312
313
const ext = platform === "windows" ? ".exe" : "" ;
313
314
const bin = `rune-languageserver-${ platform } ${ ext } ` ;
314
315
const serverDir = vscode . Uri . joinPath ( this . context . extensionUri , "server" ) ;
315
316
const dest = vscode . Uri . joinPath ( serverDir , bin ) ;
316
317
const destExists = await uriExists ( dest ) ;
317
-
318
+
318
319
// Only check for updates once every two hours.
319
320
let now = ( new Date ( ) ) . getTime ( ) / 1000 ;
320
321
let lastCheck = this . state . lastCheck ;
@@ -324,19 +325,27 @@ export class Ctx {
324
325
if ( destExists && ! timedOut ) {
325
326
return dest . fsPath ;
326
327
}
327
-
328
+
328
329
// fetch new release info
329
330
await this . state . updateLastCheck ( now ) ;
330
331
331
332
const release = await fetchRelease ( "nightly" , null ) ;
332
- const artifact = release . assets . find ( artifact => artifact . name === `rune-languageserver-${ platform } .gz` ) ;
333
- assert ( ! ! artifact , `Bad release: ${ JSON . stringify ( release ) } ` ) ;
334
-
333
+
334
+ const platform_only = `rune-languageserver-${ platform } .gz` ;
335
+ const platform_arch = `rune-languageserver-${ platform } -${ arch } .gz` ;
336
+
337
+ const artifact = release . assets . find ( artifact => artifact . name === platform_only || artifact . name === platform_arch ) ;
338
+
339
+ if ( ! artifact ) {
340
+ log . warn ( `Bad release: ${ JSON . stringify ( release ) } ` ) ;
341
+ return null ;
342
+ }
343
+
335
344
// no new release
336
345
if ( destExists && this . state . releaseId === artifact . id ) {
337
346
return dest . fsPath ;
338
347
}
339
-
348
+
340
349
// ask for update
341
350
if ( this . config . updatesAskBeforeDownload ) {
342
351
const userResponse = await vscode . window . showInformationMessage (
@@ -347,20 +356,20 @@ export class Ctx {
347
356
return dest . fsPath ;
348
357
}
349
358
}
350
-
359
+
351
360
// delete old server version
352
361
try {
353
362
await vscode . workspace . fs . delete ( dest ) ;
354
363
} catch ( exception ) {
355
364
log . debug ( "Delete of old server binary failed" , exception ) ;
356
365
}
357
-
366
+
358
367
// create server dir if missing
359
368
if ( ! await uriExists ( serverDir ) ) {
360
369
log . debug ( `Creating server dir: ${ serverDir } ` ) ;
361
370
await vscode . workspace . fs . createDirectory ( serverDir ) ;
362
371
}
363
-
372
+
364
373
// download new version
365
374
await download ( {
366
375
url : artifact . browser_download_url ,
@@ -372,11 +381,11 @@ export class Ctx {
372
381
373
382
await this . state . updateReleaseId ( release . id ) ;
374
383
return dest . fsPath ;
375
- }
376
-
384
+ }
385
+
377
386
serverPath ( ) : string | null {
378
387
return process . env . __RUNE_LSP_SERVER_DEBUG ?? this . config . serverPath ;
379
- }
388
+ }
380
389
381
390
setupStatusBar ( ) {
382
391
this . statusBar . text = "rune" ;
@@ -455,22 +464,35 @@ export class Ctx {
455
464
/**
456
465
* Function used to detect the platform we are on.
457
466
*/
458
- function detectPlatform ( ) : String | undefined {
459
- if ( process . arch === "x64" ) {
460
- switch ( process . platform ) {
461
- case "win32" :
462
- return "windows" ;
463
- case "linux" :
464
- return "linux" ;
465
- case "darwin" :
466
- return "macos" ;
467
- }
468
- }
469
-
470
- vscode . window . showErrorMessage (
471
- `Unfortunately we don't support your platform yet.
472
- You can open an issue about that [here](https://github.com/rune-rs/rune/issues).
473
- Please include (platform: ${ process . platform } , arch: ${ process . arch } ).`
474
- ) ;
475
- return undefined ;
467
+ function detectPlatform ( ) : [ String , String ] | undefined {
468
+ let platform = null ;
469
+ let arch = null ;
470
+
471
+ switch ( process . platform ) {
472
+ case "win32" :
473
+ platform = "windows" ;
474
+ case "linux" :
475
+ platform = "linux" ;
476
+ case "darwin" :
477
+ platform = "macos" ;
478
+ }
479
+
480
+ switch ( process . arch ) {
481
+ case "x64" :
482
+ arch = "x86_64" ;
483
+ case "arm64" :
484
+ arch = "aarch64" ;
485
+ }
486
+
487
+ if ( ! platform || ! arch ) {
488
+ vscode . window . showErrorMessage (
489
+ `Unfortunately we don't support your platform yet.
490
+ You can open an issue about that [here](https://github.com/rune-rs/rune/issues).
491
+ Please include (platform: ${ process . platform } , arch: ${ process . arch } ).`
492
+ ) ;
493
+
494
+ return undefined ;
495
+ }
496
+
497
+ return [ platform , arch ] ;
476
498
}
0 commit comments