Skip to content

Remove methods that no longer exist when updating test methods #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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