Skip to content

Commit ccd5a5b

Browse files
committed
correct updating of test items
1 parent 9a1b256 commit ccd5a5b

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

vscode-client/testcontrollermanager.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,36 @@ export class TestControllerManager {
348348
let tests = robotItem?.children;
349349

350350
if (robotItem?.type === "suite" && item.uri !== undefined) {
351+
if (robotItem.children === undefined) robotItem.children = [];
352+
351353
const openDoc = vscode.workspace.textDocuments.find((d) => d.uri.toString() === item.uri?.toString());
352354

353355
if (openDoc !== undefined) {
354356
tests = await this.languageClientsManager.getTestsFromDocument(openDoc, robotItem.longname, token);
357+
358+
if (tests !== undefined) {
359+
for (const test of tests) {
360+
const index = robotItem.children.findIndex((v) => v.id === test.id);
361+
if (index >= 0 && robotItem.children) {
362+
robotItem.children[index] = test;
363+
} else {
364+
robotItem.children.push(test);
365+
}
366+
}
367+
368+
const removed = robotItem.children.filter((v) => tests?.find((w) => w.id === v.id) === undefined);
369+
370+
robotItem.children = robotItem.children.filter((v) => removed.find((w) => w.id == v.id) === undefined);
371+
} else {
372+
robotItem.children = [];
373+
}
374+
375+
robotItem.children = robotItem.children.sort(
376+
(a, b) => (a.range?.start.line || -1) - (b.range?.start.line || -1)
377+
);
355378
}
356379
}
380+
357381
if (token?.isCancellationRequested) return;
358382

359383
if (robotItem) {
@@ -372,7 +396,7 @@ export class TestControllerManager {
372396
}
373397

374398
// TODO: we need a sleep after deletion here, it seem's there is a bug in vscode
375-
if (this.removeNotAddedTestItems(item, addedIds)) await sleep(500);
399+
if (this.removeNotAddedTestItems(item, addedIds)) await sleep(5);
376400
}
377401
} finally {
378402
item.busy = false;
@@ -408,7 +432,7 @@ export class TestControllerManager {
408432
}
409433

410434
// TODO: we need a sleep after deletion here, it seem's there is a bug in vscode
411-
if (this.removeNotAddedTestItems(undefined, addedIds)) await sleep(500);
435+
if (this.removeNotAddedTestItems(undefined, addedIds)) await sleep(5);
412436
}
413437
}
414438

@@ -498,7 +522,7 @@ export class TestControllerManager {
498522
this.removeWorkspaceFolderItems(w);
499523
}
500524
}
501-
await sleep(500);
525+
await sleep(5);
502526
await this.refresh();
503527
});
504528
}

0 commit comments

Comments
 (0)