@@ -131,9 +131,18 @@ function getTestItem(
131
131
}
132
132
}
133
133
134
+ interface TestRunRequestInfo {
135
+ readonly include : readonly vscode . TestItem [ ] | undefined ;
136
+ readonly exclude : readonly vscode . TestItem [ ] | undefined ;
137
+ readonly profile : vscode . TestRunProfile | undefined ;
138
+ }
139
+
134
140
export class DenoTestController implements vscode . Disposable {
135
141
#runCount = 0 ;
136
- #runs = new Map < number , vscode . TestRun > ( ) ;
142
+ #runs = new Map <
143
+ number ,
144
+ { run : vscode . TestRun ; request : TestRunRequestInfo }
145
+ > ( ) ;
137
146
#subscriptions: vscode . Disposable [ ] = [ ] ;
138
147
139
148
constructor ( client : LanguageClient ) {
@@ -148,7 +157,14 @@ export class DenoTestController implements vscode.Disposable {
148
157
) => {
149
158
const run = testController . createTestRun ( request ) ;
150
159
const id = ++ this . #runCount;
151
- this . #runs. set ( id , run ) ;
160
+ this . #runs. set ( id , {
161
+ run,
162
+ request : {
163
+ include : request . include ,
164
+ exclude : request . exclude ,
165
+ profile : request . profile ,
166
+ } ,
167
+ } ) ;
152
168
// currently on "run" is implemented and exposed
153
169
let kind : "run" | "coverage" | "debug" = "run" ;
154
170
switch ( request . profile ?. kind ) {
@@ -176,7 +192,9 @@ export class DenoTestController implements vscode.Disposable {
176
192
177
193
cancellation . onCancellationRequested ( async ( ) => {
178
194
await client . sendRequest ( testRunCancel , { id } ) ;
179
- run . end ( ) ;
195
+ // The run can be replaced
196
+ const runData = this . #runs. get ( id ) ;
197
+ runData ?. run . end ( ) ;
180
198
this . #runs. delete ( id ) ;
181
199
} ) ;
182
200
@@ -197,7 +215,7 @@ export class DenoTestController implements vscode.Disposable {
197
215
runHandler ,
198
216
true ,
199
217
undefined ,
200
- true
218
+ true ,
201
219
) ;
202
220
// TODO(@kitsonk) add debug run profile
203
221
// TODO(@kitsonk) add coverage run profile
@@ -217,7 +235,7 @@ export class DenoTestController implements vscode.Disposable {
217
235
expectedOutput ,
218
236
actualOutput ,
219
237
)
220
- : new vscode . TestMessage ( msg ) ;
238
+ : new vscode . TestMessage ( msg ) ;
221
239
222
240
if ( location ) {
223
241
testMessage . location = p2c . asLocation ( location ) ;
@@ -281,10 +299,11 @@ export class DenoTestController implements vscode.Disposable {
281
299
) ;
282
300
283
301
client . onNotification ( testRunProgress , ( { id, message } ) => {
284
- const run = this . #runs. get ( id ) ;
285
- if ( ! run ) {
302
+ const runData = this . #runs. get ( id ) ;
303
+ if ( ! runData ) {
286
304
return ;
287
305
}
306
+ const { run } = runData ;
288
307
switch ( message . type ) {
289
308
case "enqueued" :
290
309
case "started" :
@@ -321,6 +340,29 @@ export class DenoTestController implements vscode.Disposable {
321
340
run . appendOutput ( value , loc , item ) ;
322
341
break ;
323
342
}
343
+ case "restart" : {
344
+ const { enqueued } = message ;
345
+ run . end ( ) ;
346
+ const newRun = testController . createTestRun (
347
+ new vscode . TestRunRequest (
348
+ runData . request . include ,
349
+ runData . request . exclude ,
350
+ runData . request . profile ,
351
+ true ,
352
+ ) ,
353
+ ) ;
354
+ for ( const { textDocument, ids } of enqueued ) {
355
+ for ( const id of ids ) {
356
+ const item = getTestItem ( testController , { textDocument, id } ) ;
357
+ if ( ! item ) {
358
+ continue ;
359
+ }
360
+ newRun . enqueued ( item ) ;
361
+ }
362
+ }
363
+ this . #runs. set ( id , { run : newRun , request : runData . request } ) ;
364
+ break ;
365
+ }
324
366
case "end" : {
325
367
run . end ( ) ;
326
368
this . #runs. delete ( id ) ;
0 commit comments