private async processWorkspaceBuildTargetsResult()

in src/test-explorer/resolver.ts [272:334]


  private async processWorkspaceBuildTargetsResult(
    parentTest: vscode.TestItem,
    result: bsp.WorkspaceBuildTargetsResult
  ) {
    updateDescription(parentTest, 'Loading: processing target results')

    // Process the returned targets, create new test items, and store their metadata.
    const directories = new Map<string, vscode.TestItem>()
    const buildFileName = getExtensionSetting(SettingName.BUILD_FILE_NAME)
    parentTest.children.replace([])
    this.store.clearTargetIdentifiers()
    this.store.knownFiles.clear()

    result.targets.forEach(target => {
      if (!target.capabilities.canTest) return

      let relevantParent = parentTest
      if (target.baseDirectory) {
        const pathSegmentTestItems =
          this.testItemFactory.createPathSegmentTestItems(
            directories,
            target.baseDirectory
          )
        parentTest.children.add(pathSegmentTestItems.rootTestItem)
        relevantParent = pathSegmentTestItems.baseTestItem
      }

      const buildFileUri =
        target.baseDirectory && buildFileName
          ? vscode.Uri.parse(path.join(target.baseDirectory, buildFileName))
          : undefined
      // UI will group runs that have the same ID.
      const newTest = this.testItemFactory.createBuildTargetTestItem(
        target,
        buildFileUri
      )
      relevantParent.children.add(newTest)
      this.store.setTargetIdentifier(target.id, newTest)
    })

    // If no test items were added, show the getting started message as a test message overlaid on the .bazelproject file.
    // This provides an opportunity for the user to make adjustments and re-sync.
    if (parentTest.children.size === 0) {
      // Dummy test run that overlays the getting started message on the .bazelproject file.
      const run = this.store.testController.createTestRun(
        new vscode.TestRunRequest()
      )
      run.errored(parentTest, new vscode.TestMessage(gettingStartedMessage))
      run.end()

      // Link in the test explorer tree to set up the project.
      const encodedFileUri = encodeURIComponent(JSON.stringify(parentTest.uri))
      const syncFailMessage = new vscode.MarkdownString(
        `No test targets found. [Setup your project](command:vscode.open?${encodedFileUri})`
      )
      syncFailMessage.isTrusted = true
      parentTest.error = syncFailMessage
    }

    // Replace all children with the newly returned test cases.
    this.condenseTestItems(parentTest)
    updateDescription(parentTest)
  }