Skip to content

Commit 43bb545

Browse files
committed
implement workaround for vscode bug in deleting and updating testitems
1 parent 54809e6 commit 43bb545

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

vscode-client/testcontrollermanager.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { red, yellow } from "ansi-colors";
55
import * as vscode from "vscode";
66
import { DebugManager } from "./debugmanager";
77
import { LanguageClientsManager, RobotTestItem } from "./languageclientsmanger";
8-
import { Mutex, WeakValueMap } from "./utils";
8+
import { Mutex, sleep, WeakValueMap } from "./utils";
99

1010
interface RobotExecutionAttributes {
1111
id: string | undefined;
@@ -292,13 +292,17 @@ export class TestControllerManager {
292292

293293
if (robotItem) {
294294
const addedIds = new Set<string>();
295+
295296
for (const test of tests ?? []) {
296297
addedIds.add(test.id);
298+
}
299+
300+
// TODO: we need a sleep after deletion here, it seem's there is a bug in vscode
301+
if (this.removeNotAddedTestItems(item, addedIds)) await sleep(1000);
297302

303+
for (const test of tests ?? []) {
298304
await this.refreshItem(this.addOrUpdateTestItem(item, test), token);
299305
}
300-
301-
this.removeNotAddedTestItems(item, addedIds);
302306
}
303307
} finally {
304308
item.busy = false;
@@ -307,15 +311,15 @@ export class TestControllerManager {
307311
const addedIds = new Set<string>();
308312

309313
for (const workspace of vscode.workspace.workspaceFolders ?? []) {
314+
if (token?.isCancellationRequested) return;
315+
310316
if (!this.robotTestItems.has(workspace) && this.robotTestItems.get(workspace) === undefined) {
311317
this.robotTestItems.set(
312318
workspace,
313319
await this.languageClientsManager.getTestsFromWorkspace(workspace, [], token)
314320
);
315321
}
316322

317-
if (token?.isCancellationRequested) return;
318-
319323
const tests = this.robotTestItems.get(workspace);
320324

321325
if (tests) {
@@ -326,20 +330,23 @@ export class TestControllerManager {
326330
}
327331
}
328332

329-
this.removeNotAddedTestItems(undefined, addedIds);
333+
// TODO: we need a sleep after deletion here, it seem's there is a bug in vscode
334+
if (this.removeNotAddedTestItems(undefined, addedIds)) await sleep(1000);
330335
}
331336
}
332337

333338
private addOrUpdateTestItem(parentTestItem: vscode.TestItem | undefined, robotTestItem: RobotTestItem) {
334339
let testItem = parentTestItem
335340
? parentTestItem.children.get(robotTestItem.id)
336341
: this.testController.items.get(robotTestItem.id);
342+
337343
if (testItem === undefined) {
338344
testItem = this.testController.createTestItem(
339345
robotTestItem.id,
340346
robotTestItem.label,
341347
robotTestItem.uri ? vscode.Uri.parse(robotTestItem.uri) : undefined
342348
);
349+
343350
this.testItems.set(robotTestItem.id, testItem);
344351

345352
if (parentTestItem) {
@@ -364,10 +371,10 @@ export class TestControllerManager {
364371
return testItem;
365372
}
366373

367-
private removeNotAddedTestItems(parentTestItem: vscode.TestItem | undefined, addedIds: Set<string>) {
374+
private removeNotAddedTestItems(parentTestItem: vscode.TestItem | undefined, addedIds: Set<string>): boolean {
368375
const itemsToRemove = new Set<string>();
369376

370-
const items = parentTestItem?.children ?? this.testController.items;
377+
const items = parentTestItem ? parentTestItem.children : this.testController.items;
371378

372379
items.forEach((i) => {
373380
if (!addedIds.has(i.id)) {
@@ -378,6 +385,8 @@ export class TestControllerManager {
378385
items.delete(i);
379386
this.testItems.delete(i);
380387
});
388+
389+
return itemsToRemove.size > 0;
381390
}
382391

383392
private testTags = new WeakValueMap<string, vscode.TestTag>();

0 commit comments

Comments
 (0)