Skip to content

Commit 7286977

Browse files
authored
Remove methods that no longer exist when updating test methods (#1341)
1 parent 2b84f09 commit 7286977

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/commands/unitTest.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function rootItemForItem(testController: vscode.TestController, uri: vscode.Uri)
7777

7878
/** Compute `TestItem`s for `Test*` methods in `parent` */
7979
async function addTestItemsForClass(testController: vscode.TestController, parent: vscode.TestItem): Promise<void> {
80+
const newIds: string[] = [];
8081
// Get the symbols for the parent class
8182
const parentSymbols = await vscode.commands.executeCommand<vscode.DocumentSymbol[]>(
8283
"vscode.executeDocumentSymbolProvider",
@@ -98,11 +99,9 @@ async function addTestItemsForClass(testController: vscode.TestController, paren
9899
const memberName = stripClassMemberNameQuotes(clsMember.name);
99100
if (clsMember.detail == "Method" && memberName.startsWith("Test")) {
100101
const displayName = memberName.slice(4);
101-
const newItem = testController.createTestItem(
102-
`${parent.id}${methodIdSeparator}${displayName}`,
103-
displayName,
104-
parent.uri
105-
);
102+
const newId = `${parent.id}${methodIdSeparator}${displayName}`;
103+
newIds.push(newId);
104+
const newItem = testController.createTestItem(newId, displayName, parent.uri);
106105
newItem.range = clsMember.range;
107106
// Always show non-inherited methods at the top
108107
newItem.sortText = `##${displayName}`;
@@ -142,18 +141,20 @@ async function addTestItemsForClass(testController: vscode.TestController, paren
142141
);
143142
if (symbol) {
144143
const displayName = stripClassMemberNameQuotes(symbol.name).slice(4);
145-
const newItem = testController.createTestItem(
146-
`${parent.id}${methodIdSeparator}${displayName}`,
147-
displayName,
148-
parent.uri
149-
);
144+
const newId = `${parent.id}${methodIdSeparator}${displayName}`;
145+
newIds.push(newId);
146+
const newItem = testController.createTestItem(newId, displayName, parent.uri);
150147
newItem.range = symbol.range;
151148
parent.children.add(newItem);
152149
}
153150
});
154151
}
155152
}
156153
}
154+
// Remove items for any methods that have been deleted
155+
parent.children.forEach((i) => {
156+
if (!newIds.includes(i.id)) parent.children.delete(i.id);
157+
});
157158
}
158159
}
159160

@@ -1126,7 +1127,7 @@ export function setUpTestController(): vscode.Disposable[] {
11261127
const item = await getTestItemForClass(testController, e.document.uri);
11271128
if (item) {
11281129
testController.invalidateTestResults(item);
1129-
if (item.canResolveChildren && !item.children.size) {
1130+
if (item.canResolveChildren) {
11301131
// Resolve the methods
11311132
testController.resolveHandler(item);
11321133
}

0 commit comments

Comments
 (0)