private async restorePriorTests()

in src/test-explorer/resolver.ts [60:124]


  private async restorePriorTests() {
    await this.resolveRoot()
    const cachedBuildTargetsResult = this.store.getCachedBuildTargetsResult()

    // Restore the root test item and build targets.
    let addedTargets = false
    if (cachedBuildTargetsResult) {
      this.outputChannel.appendLine('Restoring prior test cases')
      const root = this.store.testController.items.get('root')
      if (root) {
        try {
          this.outputChannel.appendLine('Restoring Source Files for Root')
          await this.processWorkspaceBuildTargetsResult(
            root,
            cachedBuildTargetsResult
          )
          root.canResolveChildren = false
          addedTargets = true
        } catch (e) {
          this.outputChannel.appendLine(
            `Error restoring source files for root: ${e}`
          )
        }
      }
    }

    // Restore cached source files for targets that have them.
    const promises: Promise<void>[] = []
    for (const [key, testItem] of this.store.targetIdentifiers.entries()) {
      let cachedSourceFiles: bsp.SourcesResult | undefined
      try {
        const target: bsp.BuildTargetIdentifier = JSON.parse(key)
        const sourceParams: bsp.SourcesParams = {
          targets: [target],
        }
        cachedSourceFiles = this.store.getCachedSourcesResult(sourceParams)
      } catch (e) {
        this.outputChannel.appendLine(
          `Invalid key '${key}' when restoring source files: ${e}`
        )
      }

      if (cachedSourceFiles) {
        this.outputChannel.appendLine(
          `Restoring source files for target: ${key}`
        )
        try {
          testItem.canResolveChildren = false
          const promise = this.processTargetSourcesResult(
            testItem,
            cachedSourceFiles
          )
          promises.push(promise)
        } catch (e) {
          this.outputChannel.appendLine(
            `Error restoring source files for target: ${key}`
          )
        }
      }
    }
    await Promise.all(promises)

    // Kick off discovery of test cases in other open files that may not have been discovered yet.
    if (addedTargets) await this.resolveOpenSourceFiles()
  }