2
2
* @file This module handles running the RLS via rustup, including checking that
3
3
* rustup is installed and installing any required components/toolchains.
4
4
*/
5
+ import * as child_process from 'child_process' ;
6
+ import * as util from 'util' ;
5
7
import { window } from 'vscode' ;
6
8
7
9
import { startSpinner , stopSpinner } from './spinner' ;
8
10
import { runTaskCommand } from './tasks' ;
9
- import { withWsl } from './utils/child_process' ;
11
+
12
+ const exec = util . promisify ( child_process . exec ) ;
10
13
11
14
const REQUIRED_COMPONENTS = [ 'rust-analysis' , 'rust-src' , 'rls' ] ;
12
15
@@ -17,16 +20,13 @@ function isInstalledRegex(componentName: string): RegExp {
17
20
export interface RustupConfig {
18
21
channel : string ;
19
22
path : string ;
20
- useWSL : boolean ;
21
23
}
22
24
23
25
export async function rustupUpdate ( config : RustupConfig ) {
24
26
startSpinner ( 'Updating…' ) ;
25
27
26
28
try {
27
- const { stdout } = await withWsl ( config . useWSL ) . exec (
28
- `${ config . path } update` ,
29
- ) ;
29
+ const { stdout } = await exec ( `${ config . path } update` ) ;
30
30
31
31
// This test is imperfect because if the user has multiple toolchains installed, they
32
32
// might have one updated and one unchanged. But I don't want to go too far down the
@@ -83,20 +83,12 @@ export async function checkForRls(config: RustupConfig) {
83
83
84
84
async function hasToolchain ( config : RustupConfig ) : Promise < boolean > {
85
85
try {
86
- const { stdout } = await withWsl ( config . useWSL ) . exec (
87
- `${ config . path } toolchain list` ,
88
- ) ;
86
+ const { stdout } = await exec ( `${ config . path } toolchain list` ) ;
89
87
return stdout . includes ( config . channel ) ;
90
88
} catch ( e ) {
91
89
console . log ( e ) ;
92
- const rustupFoundButNotInWSLMode =
93
- config . useWSL && ( await hasRustup ( { useWSL : false , ...config } ) ) ;
94
-
95
90
window . showErrorMessage (
96
- rustupFoundButNotInWSLMode
97
- ? `Rustup is installed but can't be found under WSL. Ensure that
98
- invoking \`wsl rustup\` works correctly.`
99
- : 'Rustup not available. Install from https://www.rustup.rs/' ,
91
+ 'Rustup not available. Install from https://www.rustup.rs/' ,
100
92
) ;
101
93
throw e ;
102
94
}
@@ -105,11 +97,8 @@ async function hasToolchain(config: RustupConfig): Promise<boolean> {
105
97
async function tryToInstallToolchain ( config : RustupConfig ) {
106
98
startSpinner ( 'Installing toolchain…' ) ;
107
99
try {
108
- const { command, args } = withWsl ( config . useWSL ) . modifyArgs ( config . path , [
109
- 'toolchain' ,
110
- 'install' ,
111
- config . channel ,
112
- ] ) ;
100
+ const command = config . path ;
101
+ const args = [ 'toolchain' , 'install' , config . channel ] ;
113
102
await runTaskCommand ( { command, args } , 'Installing toolchain…' ) ;
114
103
if ( ! ( await hasToolchain ( config ) ) ) {
115
104
throw new Error ( ) ;
@@ -128,14 +117,14 @@ async function tryToInstallToolchain(config: RustupConfig) {
128
117
* valid listed component name.
129
118
*/
130
119
async function listComponents ( config : RustupConfig ) : Promise < string [ ] > {
131
- return withWsl ( config . useWSL )
132
- . exec ( `${ config . path } component list --toolchain ${ config . channel } ` )
133
- . then ( ( { stdout } ) =>
134
- stdout
135
- . toString ( )
136
- . replace ( '\r' , '' )
137
- . split ( '\n' ) ,
138
- ) ;
120
+ return exec (
121
+ `${ config . path } component list --toolchain ${ config . channel } ` ,
122
+ ) . then ( ( { stdout } ) =>
123
+ stdout
124
+ . toString ( )
125
+ . replace ( '\r' , '' )
126
+ . split ( '\n' ) ,
127
+ ) ;
139
128
}
140
129
141
130
async function hasRlsComponents ( config : RustupConfig ) : Promise < boolean > {
@@ -158,13 +147,14 @@ async function installRlsComponents(config: RustupConfig) {
158
147
159
148
for ( const component of REQUIRED_COMPONENTS ) {
160
149
try {
161
- const { command, args } = withWsl ( config . useWSL ) . modifyArgs ( config . path , [
150
+ const command = config . path ;
151
+ const args = [
162
152
'component' ,
163
153
'add' ,
164
154
component ,
165
155
'--toolchain' ,
166
156
config . channel ,
167
- ] ) ;
157
+ ] ;
168
158
await runTaskCommand ( { command, args } , `Installing \`${ component } \`` ) ;
169
159
170
160
const isInstalled = isInstalledRegex ( component ) ;
@@ -226,7 +216,7 @@ export function parseActiveToolchain(rustupOutput: string): string {
226
216
export async function getVersion ( config : RustupConfig ) : Promise < string > {
227
217
const versionRegex = / r u s t u p ( [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + ) / ;
228
218
229
- const output = await withWsl ( config . useWSL ) . exec ( `${ config . path } --version` ) ;
219
+ const output = await exec ( `${ config . path } --version` ) ;
230
220
const versionMatch = output . stdout . toString ( ) . match ( versionRegex ) ;
231
221
if ( versionMatch && versionMatch . length >= 2 ) {
232
222
return versionMatch [ 1 ] ;
@@ -256,8 +246,10 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
256
246
let activeChannel ;
257
247
try {
258
248
// `rustup show active-toolchain` is available since rustup 1.12.0
259
- activeChannel = withWsl ( config . useWSL )
260
- . execSync ( `${ config . path } show active-toolchain` , { cwd : wsPath } )
249
+ activeChannel = child_process
250
+ . execSync ( `${ config . path } show active-toolchain` , {
251
+ cwd : wsPath ,
252
+ } )
261
253
. toString ( )
262
254
. trim ( ) ;
263
255
// Since rustup 1.17.0 if the active toolchain is the default, we're told
@@ -267,8 +259,10 @@ export function getActiveChannel(wsPath: string, config: RustupConfig): string {
267
259
activeChannel = activeChannel . replace ( / \( .* \) $ / , '' ) ;
268
260
} catch ( e ) {
269
261
// Possibly an old rustup version, so try rustup show
270
- const showOutput = withWsl ( config . useWSL )
271
- . execSync ( `${ config . path } show` , { cwd : wsPath } )
262
+ const showOutput = child_process
263
+ . execSync ( `${ config . path } show` , {
264
+ cwd : wsPath ,
265
+ } )
272
266
. toString ( ) ;
273
267
activeChannel = parseActiveToolchain ( showOutput ) ;
274
268
}
0 commit comments