in src/test-explorer/resolver.ts [341:420]
private async resolveSourceFiles(
parentTest: vscode.TestItem,
cancellationToken?: vscode.CancellationToken
) {
const conn = await this.buildServer.getConnection()
const parentMetadata: TestCaseInfo | undefined =
this.store.testCaseMetadata.get(parentTest)
if (!parentMetadata?.target) return
const parentTarget = parentMetadata.target
const params: bsp.SourcesParams = {
targets: [parentTarget.id],
}
const result = await conn.sendRequest(
bsp.BuildTargetSources.type,
params,
cancellationToken
)
const directories = new Map<string, vscode.TestItem>()
parentTest.children.replace([])
parentTest.canResolveChildren = false
const allDocumentTestItems: vscode.TestItem[] = []
result.items.forEach(target => {
target.sources.forEach(source => {
// Parent to which the source file's test item will be added.
// If the source file is in a subdirectory, the parent will be updated based on the path.
let relevantParent = parentTest
// If the current source is not in the target's base directory, create path segments.
if (
path.resolve(path.dirname(source.uri)) !==
path.resolve(parentTarget.baseDirectory ?? '')
) {
const pathSegmentTestItems =
this.testItemFactory.createPathSegmentTestItems(
directories,
path.dirname(source.uri),
parentTarget
)
parentTest.children.add(pathSegmentTestItems.rootTestItem)
relevantParent = pathSegmentTestItems.baseTestItem
}
const newTest = this.testItemFactory.createSourceFileTestItem(
parentTarget,
source
)
this.store.knownFiles.add(source.uri)
this.syncHint.disable(newTest.uri!)
relevantParent.children.add(newTest)
allDocumentTestItems.push(newTest)
})
})
this.condenseTestItems(parentTest)
// Kick off test case resolution within each of the target's documents.
let counter = 1
for (const doc of allDocumentTestItems) {
updateDescription(
parentTest,
`Loading: analyzing test cases in file ${counter++} of ${
allDocumentTestItems.length
}`
)
await this.resolveDocumentTestCases(doc, cancellationToken)
if (doc.uri) {
// Assign a watcher to each source file's test item, to handle test case changes in the file.
const watcher = vscode.workspace.createFileSystemWatcher(doc.uri.fsPath)
watcher.onDidChange(e => {
this.resolveHandler(doc)
})
this.store.updateTestItemWatcher(doc.id, watcher)
}
}
updateDescription(parentTest)
}