private async processTargetSourcesResult()

in src/test-explorer/resolver.ts [492:578]


  private async processTargetSourcesResult(
    parentTest: vscode.TestItem,
    result: bsp.SourcesResult,
    cancellationToken?: vscode.CancellationToken
  ) {
    const parentTarget = this.store.testCaseMetadata.get(parentTest)?.target
    if (!parentTarget) return

    const languageTools =
      this.languageToolManager.getLanguageTools(parentTarget)
    result.items.forEach(item => {
      item.sources = item.sources.filter(s =>
        languageTools.isValidTestSource(s.uri)
      )
    })
    const hasValidSources = result.items.some(item => item.sources.length > 0)

    if (!hasValidSources) {
      const inferredResult = languageTools.inferSourcesFromTarget(
        parentTarget.id.uri,
        parentTarget.baseDirectory
      )
      if (inferredResult) {
        result = inferredResult
      }
    }

    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)
  }