@@ -26,7 +26,7 @@ async function exec(command, { cwd } = {}) {
26
26
}
27
27
28
28
function logErr ( e , logFn = console . warn ) {
29
- e && logFn ( "" + e )
29
+ e && logFn ( ` ${ e } ` )
30
30
}
31
31
32
32
function clearIdeRustNotifications ( prefix = "ide-rust" ) {
@@ -78,7 +78,7 @@ function rustupRun(toolchain, command, opts = {}) {
78
78
79
79
function notifyLanguageServerCommandFailed ( languageServerCmd ) {
80
80
clearIdeRustNotifications ( "ide-rust.langServerCommand" )
81
- let description =
81
+ const description =
82
82
"Make sure the **rust-analyzer** binary is installed and in `$PATH`." +
83
83
"\n\nSee https://rust-analyzer.github.io/manual.html#rust-analyzer-language-server-binary."
84
84
@@ -92,7 +92,7 @@ function notifyLanguageServerCommandFailed(languageServerCmd) {
92
92
async function rustupDefaultToolchain ( ) {
93
93
// linux: "stable-x86_64-unknown-linux-gnu (default)"
94
94
// mac: "stable (default)"
95
- let { stdout } = await exec ( "rustup default" )
95
+ const { stdout } = await exec ( "rustup default" )
96
96
return stdout . split ( "-" ) [ 0 ] . trim ( ) . split ( " " ) [ 0 ]
97
97
}
98
98
@@ -107,12 +107,12 @@ async function hasCommand(rustCommand) {
107
107
108
108
/** @returns {{ path: string; toolchain: String }[] } */
109
109
async function rustupOverrides ( ) {
110
- let { stdout } = await exec ( "rustup override list" )
110
+ const { stdout } = await exec ( "rustup override list" )
111
111
return stdout
112
- . split ( / [ \r \n ] + / g)
112
+ . split ( / [ \n \r ] + / g)
113
113
. map ( ( line ) => {
114
114
// line.trimEnd is not a function ?
115
- let lastSpace = line . trimEnd ( ) . lastIndexOf ( " " )
115
+ const lastSpace = line . trimEnd ( ) . lastIndexOf ( " " )
116
116
return {
117
117
path : line . slice ( 0 , lastSpace ) . trim ( ) ,
118
118
toolchain : line . slice ( lastSpace ) . trim ( ) ,
@@ -150,7 +150,9 @@ function shouldIgnoreProjectPath(projectPath) {
150
150
let envPath = ( ) => {
151
151
// Make sure the cargo directory is in PATH
152
152
let envPath = process . env . PATH || ""
153
- if ( ! envPath . includes ( ".cargo/bin" ) ) envPath += `:${ path . join ( os . homedir ( ) , ".cargo/bin" ) } `
153
+ if ( ! envPath . includes ( ".cargo/bin" ) ) {
154
+ envPath += `:${ path . join ( os . homedir ( ) , ".cargo/bin" ) } `
155
+ }
154
156
return envPath
155
157
}
156
158
@@ -236,23 +238,31 @@ class RustLanguageClient extends AutoLanguageClient {
236
238
this . activeOverrides = new Set ( overrides )
237
239
if ( this . activeOverrides . size > oldActive . size ) {
238
240
const confToolchain = configToolchain ( ) || ( await rustupDefaultToolchain ( ) )
239
- if ( confToolchain ) oldActive . add ( confToolchain )
241
+ if ( confToolchain ) {
242
+ oldActive . add ( confToolchain )
243
+ }
240
244
this . _promptToUpdateToolchain ( { ignore : oldActive } )
241
245
}
242
246
} catch ( e ) {
243
- if ( await hasCommand ( "rustup" ) ) logErr ( e )
247
+ if ( await hasCommand ( "rustup" ) ) {
248
+ logErr ( e )
249
+ }
244
250
}
245
251
}
246
252
247
253
/** @param {string | null } reason Reason for the restart shown in the notification */
248
254
async _restartLanguageServers ( reason ) {
249
255
await this . restartAllServers ( )
250
- if ( reason ) atom . notifications . addSuccess ( reason , { _src : "ide-rust" } )
256
+ if ( reason ) {
257
+ atom . notifications . addSuccess ( reason , { _src : "ide-rust" } )
258
+ }
251
259
}
252
260
253
261
// check for toolchain updates if installed & not dated
254
262
async _promptToUpdateToolchain ( { ignore } = { } ) {
255
- if ( ! atom . config . get ( "ide-rust.checkForToolchainUpdates" ) ) return
263
+ if ( ! atom . config . get ( "ide-rust.checkForToolchainUpdates" ) ) {
264
+ return
265
+ }
256
266
257
267
if ( ! ( await hasCommand ( "rustup" ) ) ) {
258
268
atom . config . set ( "ide-rust.checkForToolchainUpdates" , false )
@@ -263,7 +273,9 @@ class RustLanguageClient extends AutoLanguageClient {
263
273
const toolchains = new Set ( this . activeOverrides )
264
274
265
275
const confToolchain = configToolchain ( ) || ( await rustupDefaultToolchain ( ) )
266
- if ( confToolchain ) toolchains . add ( confToolchain )
276
+ if ( confToolchain ) {
277
+ toolchains . add ( confToolchain )
278
+ }
267
279
268
280
Array . from ( toolchains )
269
281
. filter ( ( toolchain ) => ! ignore || ! ignore . has ( toolchain ) )
@@ -274,9 +286,11 @@ class RustLanguageClient extends AutoLanguageClient {
274
286
toolchain = toolchain . split ( "-" ) [ 0 ]
275
287
}
276
288
277
- let { stdout : currentVersion } = await rustupRun ( confToolchain , "rustc --version" )
278
- let newVersion = await fetchLatestDist ( { toolchain, currentVersion } ) . catch ( ( ) => false )
279
- if ( ! newVersion ) return
289
+ const { stdout : currentVersion } = await rustupRun ( confToolchain , "rustc --version" )
290
+ const newVersion = await fetchLatestDist ( { toolchain, currentVersion } ) . catch ( ( ) => false )
291
+ if ( ! newVersion ) {
292
+ return
293
+ }
280
294
281
295
atom . notifications . addInfo ( `Rust \`${ toolchain } \` toolchain update available` , {
282
296
description : newVersion ,
@@ -339,7 +353,7 @@ class RustLanguageClient extends AutoLanguageClient {
339
353
if ( ! ( await exec ( "rustup --version" ) . catch ( ( ) => false ) ) ) {
340
354
this . _handleMissingRustup ( )
341
355
} else {
342
- let clicked = await atomPrompt (
356
+ const clicked = await atomPrompt (
343
357
`\`rustup\` missing ${ toolchain } toolchain` ,
344
358
{
345
359
detail : `rustup toolchain install ${ toolchain } ` ,
@@ -355,7 +369,7 @@ class RustLanguageClient extends AutoLanguageClient {
355
369
. catch ( ( e ) => {
356
370
console . warn ( e )
357
371
clearIdeRustNotifications ( )
358
- let err = ( e + "" ) . split ( "\n" )
372
+ let err = ` ${ e } ` . split ( "\n" )
359
373
err = ( err . length && err [ 0 ] ) || `Error installing rust \`${ toolchain } \``
360
374
atom . notifications . addError ( err , {
361
375
detail : "Check the toolchain is valid & connection is available" ,
@@ -374,10 +388,11 @@ class RustLanguageClient extends AutoLanguageClient {
374
388
async _handleMissingRustup ( ) {
375
389
try {
376
390
let description = "Installs from https://www.rustup.rs"
377
- if ( process . platform === "linux" )
391
+ if ( process . platform === "linux" ) {
378
392
description += ", alternatively install rustup with _`apt install rustup`_ or similar and restart."
393
+ }
379
394
380
- let clicked = await atomPrompt (
395
+ const clicked = await atomPrompt (
381
396
"`rustup` is not available" ,
382
397
{
383
398
description,
@@ -388,7 +403,7 @@ class RustLanguageClient extends AutoLanguageClient {
388
403
389
404
if ( clicked === "Install" ) {
390
405
// Install rustup and try again
391
- let installRustupPromise = installRustup ( )
406
+ const installRustupPromise = installRustup ( )
392
407
if ( this . busySignalService ) {
393
408
this . busySignalService . reportBusyWhile ( `Installing rustup` , ( ) => installRustupPromise )
394
409
}
@@ -424,7 +439,9 @@ class RustLanguageClient extends AutoLanguageClient {
424
439
// watch config toolchain updates -> check for updates if enabling
425
440
this . disposables . add (
426
441
atom . config . onDidChange ( "ide-rust.checkForToolchainUpdates" , ( { newValue : enabled } ) => {
427
- if ( enabled ) this . _promptToUpdateToolchain ( ) . catch ( logErr )
442
+ if ( enabled ) {
443
+ this . _promptToUpdateToolchain ( ) . catch ( logErr )
444
+ }
428
445
} )
429
446
)
430
447
@@ -455,7 +472,7 @@ class RustLanguageClient extends AutoLanguageClient {
455
472
456
473
postInitialization ( server ) {
457
474
// track the server so we can keep its config updated
458
- let project = new RustProject ( server , ( ) => this . busySignalService )
475
+ const project = new RustProject ( server , ( ) => this . busySignalService )
459
476
this . projects [ server . projectPath ] = project
460
477
461
478
server . process . on ( "exit" , ( ) => {
@@ -545,11 +562,11 @@ class RustLanguageClient extends AutoLanguageClient {
545
562
// only used for local variables by the language server. This makes the
546
563
// outline view cleaner and more useful.
547
564
provideOutlines ( ) {
548
- let provide = super . provideOutlines ( )
549
- let superOutline = provide . getOutline
565
+ const provide = super . provideOutlines ( )
566
+ const superOutline = provide . getOutline
550
567
551
568
provide . getOutline = async ( ...args ) => {
552
- let outline = await superOutline . apply ( this , args )
569
+ const outline = await superOutline . apply ( this , args )
553
570
outline . outlineTrees = outline . outlineTrees . filter ( ( o ) => o . icon !== "type-variable" )
554
571
return outline
555
572
}
@@ -584,7 +601,7 @@ class RustLanguageClient extends AutoLanguageClient {
584
601
* @returns {Promise<atomIde.Datatip | null> }
585
602
*/
586
603
async getDatatip ( editor , ...args ) {
587
- let datatip = await super . getDatatip ( editor , ...args )
604
+ const datatip = await super . getDatatip ( editor , ...args )
588
605
try {
589
606
if ( datatip ) {
590
607
datatip . markedStrings = datatip . markedStrings
@@ -613,7 +630,7 @@ class RustLanguageClient extends AutoLanguageClient {
613
630
*/
614
631
function convertMarkdownToSnippets ( value ) {
615
632
// even indices are text, odds are rust snippets
616
- return value . split ( / \s * ` ` ` r u s t \s * ( (?: . | \s ) + ?) \s * ` ` ` / ) . map ( ( bit , index ) => {
633
+ return value . split ( / \s * ` ` ` r u s t \s * ( [ \s . ] + ?) \s * ` ` ` / ) . map ( ( bit , index ) => {
617
634
if ( index % 2 == 0 ) {
618
635
return {
619
636
type : "markdown" ,
@@ -647,7 +664,9 @@ if (process.platform === "win32") {
647
664
envPath = ( ) => {
648
665
// Make sure the cargo directory is in PATH
649
666
let envPath = process . env . PATH || ""
650
- if ( ! envPath . includes ( ".cargo\\bin" ) ) envPath += `;${ path . join ( os . homedir ( ) , ".cargo" , "bin" ) } `
667
+ if ( ! envPath . includes ( ".cargo\\bin" ) ) {
668
+ envPath += `;${ path . join ( os . homedir ( ) , ".cargo" , "bin" ) } `
669
+ }
651
670
return envPath
652
671
}
653
672
0 commit comments