@@ -17,11 +17,9 @@ export interface CargoTaskDefinition extends vscode.TaskDefinition {
17
17
}
18
18
19
19
class CargoTaskProvider implements vscode . TaskProvider {
20
- private readonly target : vscode . WorkspaceFolder ;
21
20
private readonly config : Config ;
22
21
23
- constructor ( target : vscode . WorkspaceFolder , config : Config ) {
24
- this . target = target ;
22
+ constructor ( config : Config ) {
25
23
this . config = config ;
26
24
}
27
25
@@ -40,10 +38,12 @@ class CargoTaskProvider implements vscode.TaskProvider {
40
38
] ;
41
39
42
40
const tasks : vscode . Task [ ] = [ ] ;
43
- for ( const def of defs ) {
44
- const vscodeTask = await buildCargoTask ( this . target , { type : TASK_TYPE , command : def . command } , `cargo ${ def . command } ` , [ def . command ] , this . config . cargoRunner ) ;
45
- vscodeTask . group = def . group ;
46
- tasks . push ( vscodeTask ) ;
41
+ for ( const workspaceTarget of vscode . workspace . workspaceFolders || [ ] ) {
42
+ for ( const def of defs ) {
43
+ const vscodeTask = await buildCargoTask ( workspaceTarget , { type : TASK_TYPE , command : def . command } , `cargo ${ def . command } ` , [ def . command ] , this . config . cargoRunner ) ;
44
+ vscodeTask . group = def . group ;
45
+ tasks . push ( vscodeTask ) ;
46
+ }
47
47
}
48
48
49
49
return tasks ;
@@ -58,14 +58,19 @@ class CargoTaskProvider implements vscode.TaskProvider {
58
58
59
59
if ( definition . type === TASK_TYPE && definition . command ) {
60
60
const args = [ definition . command ] . concat ( definition . args ?? [ ] ) ;
61
-
62
- return await buildCargoTask ( this . target , definition , task . name , args , this . config . cargoRunner ) ;
61
+ if ( isWorkspaceFolder ( task . scope ) ) {
62
+ return await buildCargoTask ( task . scope , definition , task . name , args , this . config . cargoRunner ) ;
63
+ }
63
64
}
64
65
65
66
return undefined ;
66
67
}
67
68
}
68
69
70
+ function isWorkspaceFolder ( scope ?: any ) : scope is vscode . WorkspaceFolder {
71
+ return ( scope as vscode . WorkspaceFolder ) . name !== undefined ;
72
+ }
73
+
69
74
export async function buildCargoTask (
70
75
target : vscode . WorkspaceFolder ,
71
76
definition : CargoTaskDefinition ,
@@ -119,7 +124,7 @@ export async function buildCargoTask(
119
124
) ;
120
125
}
121
126
122
- export function activateTaskProvider ( target : vscode . WorkspaceFolder , config : Config ) : vscode . Disposable {
123
- const provider = new CargoTaskProvider ( target , config ) ;
127
+ export function activateTaskProvider ( config : Config ) : vscode . Disposable {
128
+ const provider = new CargoTaskProvider ( config ) ;
124
129
return vscode . tasks . registerTaskProvider ( TASK_TYPE , provider ) ;
125
130
}
0 commit comments