Skip to content

Conversation

@geoffreyheller
Copy link

Adds an option to limit quick pick queries to the closest package associated with the file currently active in the text editor.

For large projects, this helps improve query performance and relevance by avoiding unnecessary traversal of unrelated packages. If no file is open, the extension will use the workspace root as the base package.

Set bazel.limitQuickPickQueriesToNearestPackage to true to enable this feature.

Related to #451

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.

Thank you for your contribution! I have left some comments in the code, some are simply my opinion and you can of course decide on whether you agree.

As for the feature itself: I feel like limiting to the current package only could be a little to strict for many users and that the mentioned project file would be the better way to go. Maybe: Would it already serve your usecase if the list of results is ordered in a way that shows the targets of the current package first and the rest later?

Note: I am not a maintainer, so consider this just as thoughts for discussion

Copy link
Contributor

Choose a reason for hiding this comment

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

File added by mistake? Maybe you can directly add it to the .gitignore file?

but you can opt into this by enabling the **Bazel: Buildifier Fix on Format**
setting.

### Limiting quick pick queries to the nearest package
Copy link
Contributor

Choose a reason for hiding this comment

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

(opinionated) I feel like the separate output base is a configuration that will affect more users then the limiting of quick pick queries. Hence I would place the new config option below the existing one.

export function getBazelPackageFolder(fsPath: string): string | undefined {
// These are the names of the files that mark the root of a repository
// or workspace.
const PACKAGE_FILE_NAMES = ["BUILD.bazel"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Both variants are valid:

Suggested change
const PACKAGE_FILE_NAMES = ["BUILD.bazel"];
const PACKAGE_FILE_NAMES = ["BUILD.bazel", "BUILD"];

Comment on lines +143 to +144
* Search for the path to the directory that has the Bazel WORKSPACE file for
* the given file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Search for the path to the directory that has the Bazel WORKSPACE file for
* the given file.
* Search for the path to the directory that has a file marking the root of a Bazel workspace

Comment on lines +146 to +147
* If multiple directories along the path to the file have files called
* "WORKSPACE", the lowest path is returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* If multiple directories along the path to the file have files called
* "WORKSPACE", the lowest path is returned.
* If multiple directories along the path to the file have matching files, the closest one is returned.

* undefined if the target file is not found.
*/
export function getBazelWorkspaceFolder(fsPath: string): string | undefined {
function getTargetFolderForFile(
Copy link
Contributor

Choose a reason for hiding this comment

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

The word target is already overloaded in the Bazel ecosystem. How about findAncestorDirectoryContaining or something similar that better reflects the intention?

"bazel.limitQuickPickQueriesToNearestPackage": {
"type": "boolean",
"default": false,
"markdownDescription": "Limit quick pick queries to the nearest package."
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's extend the description here a little bit, so that it is not the exact same as the heading. How about:

Suggested change
"markdownDescription": "Limit quick pick queries to the nearest package."
"markdownDescription": "If active, the selection dialog for targets or packages will limit the results to the current package."

getDefaultBazelExecutablePath(),
workspaceInfo.workspaceFolder.uri.fsPath,
).queryPackages(query ?? "//...");
getWorkingDirectory(workspaceInfo),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it actually expected to limit the results to just the current package for this queryQuickPickPackage function? This means that the result will always be of length 1

@cbandera
Copy link
Contributor

cbandera commented Oct 9, 2025

Hi @geoffreyheller could you have a look at #477 and comment on whether that proposal might also serve your usecase?
Edit: Sorry, I mixed something up. The mentioned PR is unrelated.
For the problem you are concerned with I recommend #465 (which I already commented in your issue)

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.

2 participants