Skip to content

Conversation

@MichaelSbarraKodiak
Copy link

@MichaelSbarraKodiak MichaelSbarraKodiak commented Oct 17, 2025

  • Respect the user's bazel.commandLine.queryExpression when querying workspace root targets by replacing ...:* with :all if a workspace root BUILD file exists.
  • Prevents explorer view bloat from generated/shadow root targets when using custom query expressions (e.g., with aspect_rules_js).
  • Only queries root targets if the root BUILD or BUILD.bazel file is present.

Closes #480.

… targets

Respect the user's bazel.commandLine.queryExpression when querying workspace root targets by replacing ...:* with :all if a root BUILD file exists.
Prevents explorer view bloat from generated/shadow root targets when using custom query expressions (e.g., with aspect_rules_js).
Only queries root targets if the root BUILD or BUILD.bazel file is present.

Closes bazel-contrib#480.
Copy link
Contributor

@cbandera cbandera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the two findings in the code, I am not sure whether the suggested code change will actually do what you hope for.

The code in the modified function getDirectoryItems() will first collect all packages that it finds with the user specified queryExpression. And will initialize the target tree from this in buildPackageTree. After that, only the targets in the root package are queried and added to the tree.

This can be thought of as a lazy initialization of the tree. I.e. query all package names to quickly build a directory tree, but only fill in the details for those nodes of the tree that are expanded. (If you extend a node, the getChildren method will always query the targets for just this package).

The code that you have modified does only query the toplevel targets during initial initialization. And with your change, it will now not only query the toplevel targets but potentially search for targets recursively within the specified scope. This is not correct here.

Having said that, I do have to admit however that the logic is already broken in case a user has specified a custom queryExpression that only queries a subsection of a repo, because in this case, the current logic would nevertheless query and display the toplevel targets anyway. (But maybe that's not too bad...)

});
let targets: BazelTargetTreeItem[] = [];
// Only get root targets if the root package is present
const rootBuildFile =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about reusing the getBazelPackageFile() method from bazel_utils.ts?


if (rootBuildFile) {
// Replace ...:* with :all in queryExpression
const queryExpressionRoot = queryExpression.replace(/\.{3}:\*/g, ':all');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether I am missing something. Or maybe this changeset got corrupted by recent refactorings on main. But as far as I understand the code, there is no variable queryExpression here. Maybe you need to rebase onto latest master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bazel targets does not honor bazel.commandLine.queryExpression for workspace root targets

2 participants