@@ -27,7 +27,7 @@ export async function activate(context: vscode.ExtensionContext) {
27
27
async function tryActivate ( context : vscode . ExtensionContext ) {
28
28
const config = new Config ( context ) ;
29
29
const state = new PersistentState ( context . globalState ) ;
30
- const serverPath = await bootstrap ( config , state ) . catch ( err => {
30
+ const serverPath = await bootstrap ( context , config , state ) . catch ( err => {
31
31
let message = "bootstrap error. " ;
32
32
33
33
if ( err . code === "EBUSY" || err . code === "ETXTBSY" || err . code === "EPERM" ) {
@@ -157,8 +157,6 @@ export async function deactivate() {
157
157
}
158
158
159
159
async function bootstrap ( context : vscode . ExtensionContext , config : Config , state : PersistentState ) : Promise < string > {
160
- await vscode . workspace . fs . createDirectory ( config . globalStorageUri ) . then ( ) ;
161
-
162
160
const path = await getServer ( context , config , state ) ;
163
161
if ( ! path ) {
164
162
throw new Error (
@@ -244,35 +242,42 @@ async function getServer(context: vscode.ExtensionContext, config: Config, state
244
242
"arm64 darwin" : "aarch64-apple-darwin" ,
245
243
} ;
246
244
let platform = platforms [ `${ process . arch } ${ process . platform } ` ] ;
247
- if ( platform === undefined ) {
248
- await vscode . window . showErrorMessage (
249
- "Unfortunately we don't ship binaries for your platform yet. " +
250
- "You need to manually clone rust-analyzer repository and " +
251
- "run `cargo xtask install --server` to build the language server from sources. " +
252
- "If you feel that your platform should be supported, please create an issue " +
253
- "about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
254
- "will consider it."
255
- ) ;
256
- return undefined ;
257
- }
258
- if ( platform === "x86_64-unknown-linux-gnu" && isMusl ( ) ) {
259
- platform = "x86_64-unknown-linux-musl" ;
260
- }
261
- const ext = platform . indexOf ( "-windows-" ) !== - 1 ? ".exe" : "" ;
262
- const dest = vscode . Uri . joinPath ( config . globalStorageUri , `rust-analyzer-${ platform } ${ ext } ` ) ;
263
- const bundled = vscode . Uri . joinPath ( context . extensionUri , "server" , `rust-analyzer${ ext } ` ) ;
264
- const bundledExists = await vscode . workspace . fs . stat ( bundled ) . then ( ( ) => true , ( ) => false ) ;
265
- const exists = await vscode . workspace . fs . stat ( dest ) . then ( ( ) => true , ( ) => false ) ;
266
- if ( bundledExists ) {
267
- if ( ! await isNixOs ( ) ) {
268
- return bundled . fsPath ;
245
+ if ( platform ) {
246
+ if ( platform === "x86_64-unknown-linux-gnu" && isMusl ( ) ) {
247
+ platform = "x86_64-unknown-linux-musl" ;
269
248
}
270
- if ( ! exists || config . package . version !== state . serverVersion ) {
271
- await vscode . workspace . fs . copy ( bundled , dest ) ;
272
- await patchelf ( dest ) ;
249
+ const ext = platform . indexOf ( "-windows-" ) !== - 1 ? ".exe" : "" ;
250
+ const bundled = vscode . Uri . joinPath ( context . extensionUri , "server" , `rust-analyzer${ ext } ` ) ;
251
+ const bundledExists = await vscode . workspace . fs . stat ( bundled ) . then ( ( ) => true , ( ) => false ) ;
252
+ if ( bundledExists ) {
253
+ let server = bundled ;
254
+ if ( await isNixOs ( ) ) {
255
+ await vscode . workspace . fs . createDirectory ( config . globalStorageUri ) . then ( ) ;
256
+ const dest = vscode . Uri . joinPath ( config . globalStorageUri , `rust-analyzer-${ platform } ${ ext } ` ) ;
257
+ let exists = await vscode . workspace . fs . stat ( dest ) . then ( ( ) => true , ( ) => false ) ;
258
+ if ( exists && config . package . version !== state . serverVersion ) {
259
+ await vscode . workspace . fs . delete ( dest ) ;
260
+ exists = false ;
261
+ }
262
+ if ( ! exists ) {
263
+ await vscode . workspace . fs . copy ( bundled , dest ) ;
264
+ await patchelf ( dest ) ;
265
+ server = dest ;
266
+ }
267
+ }
268
+ await state . updateServerVersion ( config . package . version ) ;
269
+ return server . fsPath ;
273
270
}
274
271
}
275
- return dest . fsPath ;
272
+ await vscode . window . showErrorMessage (
273
+ "Unfortunately we don't ship binaries for your platform yet. " +
274
+ "You need to manually clone rust-analyzer repository and " +
275
+ "run `cargo xtask install --server` to build the language server from sources. " +
276
+ "If you feel that your platform should be supported, please create an issue " +
277
+ "about that [here](https://github.com/rust-analyzer/rust-analyzer/issues) and we " +
278
+ "will consider it."
279
+ ) ;
280
+ return undefined ;
276
281
}
277
282
278
283
function serverPath ( config : Config ) : string | null {
0 commit comments