Skip to content

Commit

Permalink
Remove methods that no longer exist when updating test methods (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano authored Apr 2, 2024
1 parent 2b84f09 commit 7286977
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/commands/unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function rootItemForItem(testController: vscode.TestController, uri: vscode.Uri)

/** Compute `TestItem`s for `Test*` methods in `parent` */
async function addTestItemsForClass(testController: vscode.TestController, parent: vscode.TestItem): Promise<void> {
const newIds: string[] = [];
// Get the symbols for the parent class
const parentSymbols = await vscode.commands.executeCommand<vscode.DocumentSymbol[]>(
"vscode.executeDocumentSymbolProvider",
Expand All @@ -98,11 +99,9 @@ async function addTestItemsForClass(testController: vscode.TestController, paren
const memberName = stripClassMemberNameQuotes(clsMember.name);
if (clsMember.detail == "Method" && memberName.startsWith("Test")) {
const displayName = memberName.slice(4);
const newItem = testController.createTestItem(
`${parent.id}${methodIdSeparator}${displayName}`,
displayName,
parent.uri
);
const newId = `${parent.id}${methodIdSeparator}${displayName}`;
newIds.push(newId);
const newItem = testController.createTestItem(newId, displayName, parent.uri);
newItem.range = clsMember.range;
// Always show non-inherited methods at the top
newItem.sortText = `##${displayName}`;
Expand Down Expand Up @@ -142,18 +141,20 @@ async function addTestItemsForClass(testController: vscode.TestController, paren
);
if (symbol) {
const displayName = stripClassMemberNameQuotes(symbol.name).slice(4);
const newItem = testController.createTestItem(
`${parent.id}${methodIdSeparator}${displayName}`,
displayName,
parent.uri
);
const newId = `${parent.id}${methodIdSeparator}${displayName}`;
newIds.push(newId);
const newItem = testController.createTestItem(newId, displayName, parent.uri);
newItem.range = symbol.range;
parent.children.add(newItem);
}
});
}
}
}
// Remove items for any methods that have been deleted
parent.children.forEach((i) => {
if (!newIds.includes(i.id)) parent.children.delete(i.id);
});
}
}

Expand Down Expand Up @@ -1126,7 +1127,7 @@ export function setUpTestController(): vscode.Disposable[] {
const item = await getTestItemForClass(testController, e.document.uri);
if (item) {
testController.invalidateTestResults(item);
if (item.canResolveChildren && !item.children.size) {
if (item.canResolveChildren) {
// Resolve the methods
testController.resolveHandler(item);
}
Expand Down

0 comments on commit 7286977

Please sign in to comment.