1
1
import { existsSync } from 'fs' ;
2
2
import * as path from 'path' ;
3
3
import { ExtensionContext , commands , window , workspace } from 'vscode' ;
4
- import { getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed , parseShell }
4
+ import { CargoInvocationManager } from '../../CargoInvocationManager' ;
5
+ import { getCommandForArgs , getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed , parseShell }
5
6
from '../../CommandLine' ;
6
7
import { Configuration } from '../configuration/Configuration' ;
7
8
import { ChildLogger } from '../logging/child_logger' ;
8
9
import { MissingToolsStatusBarItem } from './missing_tools_status_bar_item' ;
9
10
10
11
export class Installator {
11
- private configuration : Configuration ;
12
- private logger : ChildLogger ;
13
- private missingToolsStatusBarItem : MissingToolsStatusBarItem ;
14
- private missingTools : string [ ] ;
12
+ private _configuration : Configuration ;
13
+ private _cargoInvocationManager : CargoInvocationManager ;
14
+ private _logger : ChildLogger ;
15
+ private _missingToolsStatusBarItem : MissingToolsStatusBarItem ;
16
+ private _missingTools : string [ ] ;
15
17
16
18
public constructor (
17
19
context : ExtensionContext ,
18
20
configuration : Configuration ,
21
+ cargoInvocationManager : CargoInvocationManager ,
19
22
logger : ChildLogger
20
23
) {
21
- this . configuration = configuration ;
22
- this . logger = logger ;
24
+ this . _configuration = configuration ;
25
+ this . _cargoInvocationManager = cargoInvocationManager ;
26
+ this . _logger = logger ;
23
27
const installToolsCommandName = 'rust.install_missing_tools' ;
24
- this . missingToolsStatusBarItem = new MissingToolsStatusBarItem ( context , installToolsCommandName ) ;
25
- this . missingTools = [ ] ;
28
+ this . _missingToolsStatusBarItem = new MissingToolsStatusBarItem ( context , installToolsCommandName ) ;
29
+ this . _missingTools = [ ] ;
26
30
commands . registerCommand ( installToolsCommandName , ( ) => {
27
31
this . offerToInstallMissingTools ( ) ;
28
32
} ) ;
29
33
}
30
34
31
35
public addStatusBarItemIfSomeToolsAreMissing ( ) : void {
32
36
this . getMissingTools ( ) ;
33
- if ( this . missingTools . length === 0 ) {
37
+ if ( this . _missingTools . length === 0 ) {
34
38
return ;
35
39
}
36
- this . missingToolsStatusBarItem . show ( ) ;
40
+ this . _missingToolsStatusBarItem . show ( ) ;
37
41
}
38
42
39
43
private offerToInstallMissingTools ( ) : void {
40
44
// Plurality is important. :')
41
- const group = this . missingTools . length > 1 ? 'them' : 'it' ;
42
- const message = `You are missing ${ this . missingTools . join ( ', ' ) } . Would you like to install ${ group } ?` ;
45
+ const group = this . _missingTools . length > 1 ? 'them' : 'it' ;
46
+ const message = `You are missing ${ this . _missingTools . join ( ', ' ) } . Would you like to install ${ group } ?` ;
43
47
const option = { title : 'Install' } ;
44
48
window . showInformationMessage ( message , option ) . then ( selection => {
45
49
if ( selection !== option ) {
@@ -52,23 +56,27 @@ export class Installator {
52
56
private installMissingTools ( ) : void {
53
57
const terminal = window . createTerminal ( 'Rust tools installation' ) ;
54
58
// cargo install tool && cargo install another_tool
55
- const cargoBinPath = this . configuration . getCargoPath ( ) ;
59
+ const { executable : cargoExecutable , args : cargoArgs } = this . _cargoInvocationManager . getExecutableAndArgs ( ) ;
56
60
const shell = parseShell ( workspace . getConfiguration ( 'terminal' ) [ 'integrated' ] [ 'shell' ] [ 'windows' ] ) ;
57
- const statements = this . missingTools . map ( tool => `${ cargoBinPath } install ${ tool } ` ) ;
61
+
62
+ const statements = this . _missingTools . map ( tool => {
63
+ const args = [ cargoExecutable , ...cargoArgs , 'install' , tool ] ;
64
+ return getCommandForArgs ( shell , args ) ;
65
+ } ) ;
58
66
const command = getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed ( shell , statements ) ;
59
67
terminal . sendText ( command ) ;
60
68
terminal . show ( ) ;
61
- this . missingToolsStatusBarItem . hide ( ) ;
69
+ this . _missingToolsStatusBarItem . hide ( ) ;
62
70
}
63
71
64
72
private getMissingTools ( ) : void {
65
- const logger = this . logger . createChildLogger ( 'getMissingTools(): ' ) ;
73
+ const logger = this . _logger . createChildLogger ( 'getMissingTools(): ' ) ;
66
74
const pathDirectories : string [ ] = ( process . env . PATH || '' ) . split ( path . delimiter ) ;
67
75
logger . debug ( `pathDirectories=${ JSON . stringify ( pathDirectories ) } ` ) ;
68
76
const tools : { [ tool : string ] : string | undefined } = {
69
- 'racer' : this . configuration . getPathToRacer ( ) ,
70
- 'rustfmt' : this . configuration . getRustfmtPath ( ) ,
71
- 'rustsym' : this . configuration . getRustsymPath ( )
77
+ 'racer' : this . _configuration . getPathToRacer ( ) ,
78
+ 'rustfmt' : this . _configuration . getRustfmtPath ( ) ,
79
+ 'rustsym' : this . _configuration . getRustsymPath ( )
72
80
} ;
73
81
logger . debug ( `tools=${ JSON . stringify ( tools ) } ` ) ;
74
82
const keys = Object . keys ( tools ) ;
@@ -99,7 +107,7 @@ export class Installator {
99
107
// The tool wasn't found, we should install it
100
108
return tool ;
101
109
} ) . filter ( tool => tool !== undefined ) ;
102
- this . missingTools = < string [ ] > missingTools ;
103
- logger . debug ( `this.missingTools = ${ JSON . stringify ( this . missingTools ) } ` ) ;
110
+ this . _missingTools = < string [ ] > missingTools ;
111
+ logger . debug ( `this.missingTools = ${ JSON . stringify ( this . _missingTools ) } ` ) ;
104
112
}
105
113
}
0 commit comments