in src/test-explorer/resolver.ts [279:334]
private async expandTargetsForDocument(doc: vscode.TextDocument) {
if (doc.uri.scheme !== 'file') return
// Avoid checking files that are already known, or not test files.
if (this.store.knownFiles.has(doc.uri.toString())) return
const tools = this.languageToolManager.getLanguageToolsForFile(doc)
const docInfo = await tools.getDocumentTestCases(
doc.uri,
this.repoRoot ?? ''
)
if (!docInfo.isTestFile) return
this.store.knownFiles.add(doc.uri.toString())
const conn = await this.buildServer.getConnection()
const params: bsp.InverseSourcesParams = {
textDocument: {
uri: doc.uri.toString(),
},
}
let result: bsp.InverseSourcesResult | undefined
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: `Getting target for ${path.basename(doc.uri.fsPath)}.`,
cancellable: true,
},
async (progress, token) => {
try {
result = await conn.sendRequest(
bsp.BuildTargetInverseSources.type,
params,
token
)
} catch (e) {
result = undefined
}
}
)
if (!result) {
this.outputChannel.appendLine(
`Unable to determine target for ${doc.fileName}.`
)
return
}
for (const target of result.targets) {
// Put this file under the first matching target, in the rare event that a test is part of multiple targets.
const targetItem = this.store.getTargetIdentifier(target)
if (targetItem) {
await this.resolveHandler(targetItem)
return
}
}
this.syncHint.enable(doc.uri, this.repoRoot ?? '', docInfo)
}