private async getDirectoryItems()

in src/workspace-tree/bazel_workspace_folder_tree_item.ts [148:189]


  private async getDirectoryItems(): Promise<IBazelTreeItem[]> {
    // Retrieve the list of all packages underneath the current workspace
    // folder. Note that if the workspace folder is not the root of a Bazel
    // workspace but is instead a folder underneath it, we query for *only* the
    // packages under that folder (including the folder itself). This lets us
    // have a VS Code workspace that is pointed at a subpackage of a large
    // workspace without the performance penalty of querying the entire
    // workspace.
    if (!this.workspaceInfo) {
      return Promise.resolve([]);
    }
    const workspacePath = this.workspaceInfo.workspaceFolder.uri.fsPath;
    const packagePaths = await new BazelQuery(
      getDefaultBazelExecutablePath(),
      workspacePath,
      "...:*",
      [],
    ).queryPackages();
    const topLevelItems: BazelPackageTreeItem[] = [];
    this.buildPackageTree(
      packagePaths,
      0,
      packagePaths.length,
      topLevelItems,
      "",
    );

    // Now collect any targets in the directory also (this can fail since
    // there might not be a BUILD files at this level (but down levels)).
    const queryResult = await new BazelQuery(
      getDefaultBazelExecutablePath(),
      workspacePath,
      `:all`,
      [],
      true,
    ).queryTargets([], /* sortByRuleName: */ true);
    const targets = queryResult.target.map((target: blaze_query.Target) => {
      return new BazelTargetTreeItem(this.workspaceInfo, target);
    });

    return Promise.resolve((topLevelItems as IBazelTreeItem[]).concat(targets));
  }