@@ -2,22 +2,20 @@ import * as vscode from "vscode";
2
2
import * as toolchain from "./toolchain" ;
3
3
import type { Config } from "./config" ;
4
4
import { log } from "./util" ;
5
- import { unwrapUndefinable } from "./undefinable" ;
6
5
7
6
// This ends up as the `type` key in tasks.json. RLS also uses `cargo` and
8
7
// our configuration should be compatible with it so use the same key.
9
8
export const TASK_TYPE = "cargo" ;
10
9
export const TASK_SOURCE = "rust" ;
11
10
12
- export interface CargoTaskDefinition extends vscode . TaskDefinition {
13
- command ? : string ;
14
- args ? : string [ ] ;
11
+ export interface RustTargetDefinition extends vscode . TaskDefinition {
12
+ program : string ;
13
+ args : string [ ] ;
15
14
cwd ?: string ;
16
15
env ?: { [ key : string ] : string } ;
17
- overrideCargo ?: string ;
18
16
}
19
17
20
- class CargoTaskProvider implements vscode . TaskProvider {
18
+ class RustTaskProvider implements vscode . TaskProvider {
21
19
private readonly config : Config ;
22
20
23
21
constructor ( config : Config ) {
@@ -39,14 +37,15 @@ class CargoTaskProvider implements vscode.TaskProvider {
39
37
{ command : "run" , group : undefined } ,
40
38
] ;
41
39
40
+ const cargoPath = await toolchain . cargoPath ( ) ;
41
+
42
42
const tasks : vscode . Task [ ] = [ ] ;
43
43
for ( const workspaceTarget of vscode . workspace . workspaceFolders || [ ] ) {
44
44
for ( const def of defs ) {
45
- const vscodeTask = await buildCargoTask (
45
+ const vscodeTask = await buildRustTask (
46
46
workspaceTarget ,
47
- { type : TASK_TYPE , command : def . command } ,
47
+ { type : TASK_TYPE , program : cargoPath , args : [ def . command ] } ,
48
48
`cargo ${ def . command } ` ,
49
- [ def . command ] ,
50
49
this . config . problemMatcher ,
51
50
this . config . cargoRunner ,
52
51
) ;
@@ -63,15 +62,13 @@ class CargoTaskProvider implements vscode.TaskProvider {
63
62
// we need to inform VSCode how to execute that command by creating
64
63
// a ShellExecution for it.
65
64
66
- const definition = task . definition as CargoTaskDefinition ;
65
+ const definition = task . definition as RustTargetDefinition ;
67
66
68
- if ( definition . type === TASK_TYPE && definition . command ) {
69
- const args = [ definition . command ] . concat ( definition . args ?? [ ] ) ;
70
- return await buildCargoTask (
67
+ if ( definition . type === TASK_TYPE ) {
68
+ return await buildRustTask (
71
69
task . scope ,
72
70
definition ,
73
71
task . name ,
74
- args ,
75
72
this . config . problemMatcher ,
76
73
this . config . cargoRunner ,
77
74
) ;
@@ -81,11 +78,10 @@ class CargoTaskProvider implements vscode.TaskProvider {
81
78
}
82
79
}
83
80
84
- export async function buildCargoTask (
81
+ export async function buildRustTask (
85
82
scope : vscode . WorkspaceFolder | vscode . TaskScope | undefined ,
86
- definition : CargoTaskDefinition ,
83
+ definition : RustTargetDefinition ,
87
84
name : string ,
88
- args : string [ ] ,
89
85
problemMatcher : string [ ] ,
90
86
customRunner ?: string ,
91
87
throwOnError : boolean = false ,
@@ -95,7 +91,12 @@ export async function buildCargoTask(
95
91
if ( customRunner ) {
96
92
const runnerCommand = `${ customRunner } .buildShellExecution` ;
97
93
try {
98
- const runnerArgs = { kind : TASK_TYPE , args, cwd : definition . cwd , env : definition . env } ;
94
+ const runnerArgs = {
95
+ kind : TASK_TYPE ,
96
+ args : definition . args ,
97
+ cwd : definition . cwd ,
98
+ env : definition . env ,
99
+ } ;
99
100
const customExec = await vscode . commands . executeCommand ( runnerCommand , runnerArgs ) ;
100
101
if ( customExec ) {
101
102
if ( customExec instanceof vscode . ShellExecution ) {
@@ -113,16 +114,7 @@ export async function buildCargoTask(
113
114
}
114
115
115
116
if ( ! exec ) {
116
- // Check whether we must use a user-defined substitute for cargo.
117
- // Split on spaces to allow overrides like "wrapper cargo".
118
- const overrideCargo = definition . overrideCargo ?? definition . overrideCargo ;
119
- const cargoPath = await toolchain . cargoPath ( ) ;
120
- const cargoCommand = overrideCargo ?. split ( " " ) ?? [ cargoPath ] ;
121
-
122
- const fullCommand = [ ...cargoCommand , ...args ] ;
123
-
124
- const processName = unwrapUndefinable ( fullCommand [ 0 ] ) ;
125
- exec = new vscode . ProcessExecution ( processName , fullCommand . slice ( 1 ) , definition ) ;
117
+ exec = new vscode . ProcessExecution ( definition . program , definition . args , definition ) ;
126
118
}
127
119
128
120
return new vscode . Task (
@@ -138,6 +130,6 @@ export async function buildCargoTask(
138
130
}
139
131
140
132
export function activateTaskProvider ( config : Config ) : vscode . Disposable {
141
- const provider = new CargoTaskProvider ( config ) ;
133
+ const provider = new RustTaskProvider ( config ) ;
142
134
return vscode . tasks . registerTaskProvider ( TASK_TYPE , provider ) ;
143
135
}
0 commit comments