@@ -25,52 +25,12 @@ impl flags::Install {
25
25
}
26
26
}
27
27
28
- #[ derive( Clone , Copy ) ]
29
- pub ( crate ) enum ClientOpt {
30
- VsCode ,
31
- VsCodeExploration ,
32
- VsCodeInsiders ,
33
- VsCodium ,
34
- VsCodeOss ,
35
- Any ,
28
+ #[ derive( Clone ) ]
29
+ pub ( crate ) struct ClientOpt {
30
+ pub ( crate ) code_bin : Option < String > ,
36
31
}
37
32
38
- impl ClientOpt {
39
- pub ( crate ) const fn as_cmds ( & self ) -> & ' static [ & ' static str ] {
40
- match self {
41
- ClientOpt :: VsCode => & [ "code" ] ,
42
- ClientOpt :: VsCodeExploration => & [ "code-exploration" ] ,
43
- ClientOpt :: VsCodeInsiders => & [ "code-insiders" ] ,
44
- ClientOpt :: VsCodium => & [ "codium" ] ,
45
- ClientOpt :: VsCodeOss => & [ "code-oss" ] ,
46
- ClientOpt :: Any => & [ "code" , "code-exploration" , "code-insiders" , "codium" , "code-oss" ] ,
47
- }
48
- }
49
- }
50
-
51
- impl Default for ClientOpt {
52
- fn default ( ) -> Self {
53
- ClientOpt :: Any
54
- }
55
- }
56
-
57
- impl std:: str:: FromStr for ClientOpt {
58
- type Err = anyhow:: Error ;
59
-
60
- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
61
- [
62
- ClientOpt :: VsCode ,
63
- ClientOpt :: VsCodeExploration ,
64
- ClientOpt :: VsCodeInsiders ,
65
- ClientOpt :: VsCodium ,
66
- ClientOpt :: VsCodeOss ,
67
- ]
68
- . iter ( )
69
- . copied ( )
70
- . find ( |c| [ s] == c. as_cmds ( ) )
71
- . ok_or_else ( || anyhow:: format_err!( "no such client" ) )
72
- }
73
- }
33
+ const VS_CODES : & [ & str ] = & [ "code" , "code-exploration" , "code-insiders" , "codium" , "code-oss" ] ;
74
34
75
35
pub ( crate ) struct ServerOpt {
76
36
pub ( crate ) malloc : Malloc ,
@@ -118,30 +78,49 @@ fn fix_path_for_mac() -> Result<()> {
118
78
fn install_client ( client_opt : ClientOpt ) -> Result < ( ) > {
119
79
let _dir = pushd ( "./editors/code" ) ;
120
80
121
- let find_code = |f : fn ( & str ) -> bool | -> Result < & ' static str > {
122
- client_opt. as_cmds ( ) . iter ( ) . copied ( ) . find ( |bin| f ( bin) ) . ok_or_else ( || {
123
- format_err ! ( "Can't execute `code --version`. Perhaps it is not in $PATH?" )
124
- } )
125
- } ;
126
-
127
- let installed_extensions = if cfg ! ( unix) {
81
+ // Package extension.
82
+ if cfg ! ( unix) {
128
83
cmd ! ( "npm --version" ) . run ( ) . context ( "`npm` is required to build the VS Code plugin" ) ?;
129
84
cmd ! ( "npm ci" ) . run ( ) ?;
130
85
131
86
cmd ! ( "npm run package --scripts-prepend-node-path" ) . run ( ) ?;
132
-
133
- let code = find_code ( |bin| cmd ! ( "{bin} --version" ) . read ( ) . is_ok ( ) ) ?;
134
- cmd ! ( "{code} --install-extension rust-analyzer.vsix --force" ) . run ( ) ?;
135
- cmd ! ( "{code} --list-extensions" ) . read ( ) ?
136
87
} else {
137
88
cmd ! ( "cmd.exe /c npm --version" )
138
89
. run ( )
139
90
. context ( "`npm` is required to build the VS Code plugin" ) ?;
140
91
cmd ! ( "cmd.exe /c npm ci" ) . run ( ) ?;
141
92
142
93
cmd ! ( "cmd.exe /c npm run package" ) . run ( ) ?;
94
+ } ;
95
+
96
+ // Find the appropriate VS Code binary.
97
+ let lifetime_extender;
98
+ let candidates: & [ & str ] = match client_opt. code_bin . as_deref ( ) {
99
+ Some ( it) => {
100
+ lifetime_extender = [ it] ;
101
+ & lifetime_extender[ ..]
102
+ }
103
+ None => VS_CODES ,
104
+ } ;
105
+ let code = candidates
106
+ . iter ( )
107
+ . copied ( )
108
+ . find ( |& bin| {
109
+ if cfg ! ( unix) {
110
+ cmd ! ( "{bin} --version" ) . read ( ) . is_ok ( )
111
+ } else {
112
+ cmd ! ( "cmd.exe /c {bin}.cmd --version" ) . read ( ) . is_ok ( )
113
+ }
114
+ } )
115
+ . ok_or_else ( || {
116
+ format_err ! ( "Can't execute `{} --version`. Perhaps it is not in $PATH?" , candidates[ 0 ] )
117
+ } ) ?;
143
118
144
- let code = find_code ( |bin| cmd ! ( "cmd.exe /c {bin}.cmd --version" ) . read ( ) . is_ok ( ) ) ?;
119
+ // Install & verify.
120
+ let installed_extensions = if cfg ! ( unix) {
121
+ cmd ! ( "{code} --install-extension rust-analyzer.vsix --force" ) . run ( ) ?;
122
+ cmd ! ( "{code} --list-extensions" ) . read ( ) ?
123
+ } else {
145
124
cmd ! ( "cmd.exe /c {code}.cmd --install-extension rust-analyzer.vsix --force" ) . run ( ) ?;
146
125
cmd ! ( "cmd.exe /c {code}.cmd --list-extensions" ) . read ( ) ?
147
126
} ;
0 commit comments