@@ -25,19 +25,19 @@ interface LastClientError {
2525export class Ctx {
2626 readonly context : vscode . ExtensionContext ;
2727 readonly config : Config ;
28- readonly state : PersistentState ;
28+ readonly state : PersistentState ;
2929 readonly statusBar : vscode . StatusBarItem ;
30-
30+
3131 // Stored initialization error. Cleared when reloaded.
3232 lastClientError : LastClientError | null ;
3333 client : lc . LanguageClient | null ;
34- commands : { [ key :string ] : lc . Disposable } ;
34+ commands : { [ key : string ] : lc . Disposable } ;
3535 stopped : boolean ;
3636
3737 constructor ( context : vscode . ExtensionContext ) {
3838 this . context = context ;
3939 this . config = new Config ( context ) ;
40- this . state = new PersistentState ( context . globalState ) ;
40+ this . state = new PersistentState ( context . globalState ) ;
4141 this . statusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left ) ;
4242 this . lastClientError = null ;
4343 this . client = null ;
@@ -75,7 +75,7 @@ export class Ctx {
7575 }
7676
7777 this . setupStatusBar ( ) ;
78- }
78+ }
7979
8080 command ( name : string , callback : ( ...args : any [ ] ) => any ) {
8181 if ( ! this . commands [ name ] ) {
@@ -152,11 +152,11 @@ export class Ctx {
152152 let [ code , out , err ] : [ number | null , string , string ] = await new Promise ( ( resolve , _ ) => {
153153 let stdout = "" ;
154154 let stderr = "" ;
155-
155+
156156 cargoVersion . stdout . on ( "data" , ( chunk ) => {
157157 stdout += chunk ;
158158 } ) ;
159-
159+
160160 cargoVersion . stderr . on ( "data" , ( chunk ) => {
161161 stderr += chunk ;
162162 } ) ;
@@ -211,7 +211,7 @@ export class Ctx {
211211 child . stderr . setEncoding ( 'utf8' ) ;
212212 child . stdout . setEncoding ( 'utf8' ) ;
213213 let out = rl . createInterface ( child . stdout , child . stdin ) ;
214-
214+
215215 this . statusBar . text = `rune: cargo build -p ${ name } ` ;
216216 this . statusBar . tooltip = `rune: building package ${ name } , to use as rune language server` ;
217217 this . statusBar . backgroundColor = new vscode . ThemeColor ( 'statusBarItem.warningBackground' ) ;
@@ -273,10 +273,10 @@ export class Ctx {
273273
274274 if ( explicitPath ) {
275275 if ( explicitPath . startsWith ( "~/" ) ) {
276- return { kind : "languageserver " , path : os . homedir ( ) + explicitPath . slice ( "~" . length ) } ;
276+ return { kind : "cli " , path : os . homedir ( ) + explicitPath . slice ( "~" . length ) } ;
277277 }
278278
279- return { kind : "languageserver " , path : explicitPath } ;
279+ return { kind : "cli " , path : explicitPath } ;
280280 }
281281
282282 const cargoPackage = this . config . serverCargoPackage ;
@@ -297,24 +297,25 @@ export class Ctx {
297297 return null ;
298298 }
299299
300- return { kind : "languageserver " , path } ;
300+ return { kind : "cli " , path } ;
301301 }
302-
302+
303303 async downloadServer ( ) : Promise < string | null > {
304- // unknown platform => no download available
305- const platform = detectPlatform ( ) ;
304+ const platformArch = detectPlatform ( ) ;
306305
307- if ( ! platform ) {
306+ if ( ! platformArch ) {
308307 return null ;
309308 }
310-
309+
310+ const [ platform , arch ] = platformArch ;
311+
311312 // platform specific binary name / path
312313 const ext = platform === "windows" ? ".exe" : "" ;
313314 const bin = `rune-languageserver-${ platform } ${ ext } ` ;
314315 const serverDir = vscode . Uri . joinPath ( this . context . extensionUri , "server" ) ;
315316 const dest = vscode . Uri . joinPath ( serverDir , bin ) ;
316317 const destExists = await uriExists ( dest ) ;
317-
318+
318319 // Only check for updates once every two hours.
319320 let now = ( new Date ( ) ) . getTime ( ) / 1000 ;
320321 let lastCheck = this . state . lastCheck ;
@@ -324,19 +325,27 @@ export class Ctx {
324325 if ( destExists && ! timedOut ) {
325326 return dest . fsPath ;
326327 }
327-
328+
328329 // fetch new release info
329330 await this . state . updateLastCheck ( now ) ;
330331
331332 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+
335344 // no new release
336345 if ( destExists && this . state . releaseId === artifact . id ) {
337346 return dest . fsPath ;
338347 }
339-
348+
340349 // ask for update
341350 if ( this . config . updatesAskBeforeDownload ) {
342351 const userResponse = await vscode . window . showInformationMessage (
@@ -347,20 +356,20 @@ export class Ctx {
347356 return dest . fsPath ;
348357 }
349358 }
350-
359+
351360 // delete old server version
352361 try {
353362 await vscode . workspace . fs . delete ( dest ) ;
354363 } catch ( exception ) {
355364 log . debug ( "Delete of old server binary failed" , exception ) ;
356365 }
357-
366+
358367 // create server dir if missing
359368 if ( ! await uriExists ( serverDir ) ) {
360369 log . debug ( `Creating server dir: ${ serverDir } ` ) ;
361370 await vscode . workspace . fs . createDirectory ( serverDir ) ;
362371 }
363-
372+
364373 // download new version
365374 await download ( {
366375 url : artifact . browser_download_url ,
@@ -372,11 +381,11 @@ export class Ctx {
372381
373382 await this . state . updateReleaseId ( release . id ) ;
374383 return dest . fsPath ;
375- }
376-
384+ }
385+
377386 serverPath ( ) : string | null {
378387 return process . env . __RUNE_LSP_SERVER_DEBUG ?? this . config . serverPath ;
379- }
388+ }
380389
381390 setupStatusBar ( ) {
382391 this . statusBar . text = "rune" ;
@@ -455,22 +464,35 @@ export class Ctx {
455464/**
456465 * Function used to detect the platform we are on.
457466 */
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 ] ;
476498}
0 commit comments