Skip to content

Commit abdbce0

Browse files
authored
feat(config): add an option to fully disable queries to support large workspaces where performance is an issue (#1)
feat(config): add an option to fully disable queries to support large workspaces where performance is an issue
1 parent 7b6f85f commit abdbce0

File tree

9 files changed

+64
-7
lines changed

9 files changed

+64
-7
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ this extension does not automatically _fix_ lint warnings during formatting,
3636
but you can opt into this by enabling the **Bazel: Buildifier Fix on Format**
3737
setting.
3838

39+
### Disabling Bazel Queries
40+
41+
If you experience performance issues or want to reduce Bazel server load, you can disable all Bazel queries by setting **Bazel: Enable Queries** to `false`. When disabled, the following features will not work:
42+
43+
- Bazel Targets tree view
44+
- Target completion in quick pick dialogs
45+
- CodeLens actions in BUILD files
46+
- Go-to-definition for Bazel targets
47+
- Symbol provider for BUILD files
48+
49+
This setting is enabled by default to provide the full feature set, but disabling it can significantly improve performance in large workspaces.
50+
3951
### Using a separate output base
4052

4153
By default this extension will use the default output base for running queries. This will cause builds to block queries, potentially causing degraded performance. In Bazel versions since 7.1 it is safe to disable this by changing the `bazel.queriesShareServer` setting to `false`. In earlier versions it can be safely disabled after adding the convenience symlinks to `.bazelignore`, for example:

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@
149149
"default": false,
150150
"markdownDescription": "Whether to add a CodeLens to `BUILD`/`BUILD.bazel` files to provide actions while browsing the file."
151151
},
152+
"bazel.enableQueries": {
153+
"type": "boolean",
154+
"default": true,
155+
"markdownDescription": "Whether to enable Bazel queries. When disabled, all query-dependent features (workspace tree, target completion, code lens, go-to-definition) will be disabled to improve performance and reduce Bazel server load."
156+
},
152157
"bazel.pathsToIgnore": {
153158
"type": "array",
154159
"items": {

src/bazel/bazel_quickpick.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as vscode from "vscode";
1616

17-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
17+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
1818
import { IBazelCommandAdapter, IBazelCommandOptions } from "./bazel_command";
1919
import { BazelQuery } from "./bazel_query";
2020
import { BazelWorkspaceInfo } from "./bazel_workspace_info";
@@ -97,6 +97,10 @@ export async function queryQuickPickTargets({
9797
query,
9898
workspaceInfo,
9999
}: QuickPickParams): Promise<BazelTargetQuickPick[]> {
100+
if (!areBazelQueriesEnabled()) {
101+
return [];
102+
}
103+
100104
if (workspaceInfo === undefined) {
101105
// Ask the user to pick a workspace, if we don't have one, yet
102106
workspaceInfo = await pickBazelWorkspace();
@@ -133,6 +137,10 @@ export async function queryQuickPickPackage({
133137
query,
134138
workspaceInfo,
135139
}: QuickPickParams): Promise<BazelTargetQuickPick[]> {
140+
if (!areBazelQueriesEnabled()) {
141+
return [];
142+
}
143+
136144
if (workspaceInfo === undefined) {
137145
// Ask the user to pick a workspace, if we don't have one, yet
138146
workspaceInfo = await pickBazelWorkspace();

src/codelens/bazel_build_code_lens_provider.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as vscode from "vscode";
1616

1717
import { BazelWorkspaceInfo, QueryLocation } from "../bazel";
1818
import { getTargetsForBuildFile } from "../bazel";
19-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
19+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
2020
import { blaze_query } from "../protos";
2121
import { CodeLensCommandAdapter } from "./code_lens_command_adapter";
2222

@@ -69,7 +69,8 @@ export class BazelBuildCodeLensProvider implements vscode.CodeLensProvider {
6969
);
7070

7171
vscode.workspace.onDidChangeConfiguration((change) => {
72-
if (change.affectsConfiguration("bazel.enableCodeLens")) {
72+
if (change.affectsConfiguration("bazel.enableCodeLens") ||
73+
change.affectsConfiguration("bazel.enableQueries")) {
7374
this.onDidChangeCodeLensesEmitter.fire();
7475
}
7576
});
@@ -91,6 +92,10 @@ export class BazelBuildCodeLensProvider implements vscode.CodeLensProvider {
9192
return [];
9293
}
9394

95+
if (!areBazelQueriesEnabled()) {
96+
return [];
97+
}
98+
9499
if (document.isDirty) {
95100
// Don't show code lenses for dirty BUILD files; we can't reliably
96101
// determine what the build targets in it are until it is saved and we can

src/definition/bazel_goto_definition_provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from "vscode";
2323
import { Utils } from "vscode-uri";
2424
import { BazelQuery, BazelWorkspaceInfo, QueryLocation } from "../bazel";
25-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
25+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
2626
import { blaze_query } from "../protos";
2727

2828
// LABEL_REGEX matches label strings, e.g. @r//x/y/z:abc
@@ -32,6 +32,10 @@ export async function targetToUri(
3232
targetText: string,
3333
workingDirectory: Uri,
3434
): Promise<QueryLocation | undefined> {
35+
if (!areBazelQueriesEnabled()) {
36+
return null;
37+
}
38+
3539
const match = LABEL_REGEX.exec(targetText);
3640

3741
const targetName = match[1];

src/extension/configuration.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ export function getDefaultBazelExecutablePath(): string {
3232
}
3333
return bazelExecutable;
3434
}
35+
36+
/**
37+
* Checks if Bazel queries are enabled in the workspace configuration.
38+
*
39+
* @returns True if Bazel queries are enabled (default), false otherwise.
40+
*/
41+
export function areBazelQueriesEnabled(): boolean {
42+
const bazelConfig = vscode.workspace.getConfiguration("bazel");
43+
return bazelConfig.get<boolean>("enableQueries", true);
44+
}

src/symbols/bazel_target_symbol_provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ import { DocumentSymbolProvider } from "vscode";
1717

1818
import { BazelWorkspaceInfo, QueryLocation } from "../bazel";
1919
import { getTargetsForBuildFile } from "../bazel";
20-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
20+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
2121
import { blaze_query } from "../protos";
2222

2323
/** Provids Symbols for targets in Bazel BUILD files. */
2424
export class BazelTargetSymbolProvider implements DocumentSymbolProvider {
2525
public async provideDocumentSymbols(
2626
document: vscode.TextDocument,
2727
): Promise<vscode.SymbolInformation[] | vscode.DocumentSymbol[]> {
28+
if (!areBazelQueriesEnabled()) {
29+
return [];
30+
}
31+
2832
const workspaceInfo = BazelWorkspaceInfo.fromDocument(document);
2933
if (workspaceInfo === undefined) {
3034
// Not in a Bazel Workspace.

src/workspace-tree/bazel_package_tree_item.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
IBazelCommandAdapter,
2020
IBazelCommandOptions,
2121
} from "../bazel";
22-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
22+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
2323
import { blaze_query } from "../protos";
2424
import { BazelTargetTreeItem } from "./bazel_target_tree_item";
2525
import { IBazelTreeItem } from "./bazel_tree_item";
@@ -56,6 +56,11 @@ export class BazelPackageTreeItem
5656
}
5757

5858
public async getChildren(): Promise<IBazelTreeItem[]> {
59+
// If queries are disabled, just return subpackages
60+
if (!areBazelQueriesEnabled()) {
61+
return this.directSubpackages as IBazelTreeItem[];
62+
}
63+
5964
const queryResult = await new BazelQuery(
6065
getDefaultBazelExecutablePath(),
6166
this.workspaceInfo.bazelWorkspacePath,

src/workspace-tree/bazel_workspace_folder_tree_item.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as vscode from "vscode";
1616
import { BazelWorkspaceInfo, BazelQuery } from "../bazel";
17-
import { getDefaultBazelExecutablePath } from "../extension/configuration";
17+
import { getDefaultBazelExecutablePath, areBazelQueriesEnabled } from "../extension/configuration";
1818
import { blaze_query } from "../protos";
1919
import { BazelPackageTreeItem } from "./bazel_package_tree_item";
2020
import { BazelTargetTreeItem } from "./bazel_target_tree_item";
@@ -150,6 +150,10 @@ export class BazelWorkspaceFolderTreeItem implements IBazelTreeItem {
150150
* Returns a promise for an array of tree items representing build items.
151151
*/
152152
private async getDirectoryItems(): Promise<IBazelTreeItem[]> {
153+
if (!areBazelQueriesEnabled()) {
154+
return Promise.resolve([] as IBazelTreeItem[]);
155+
}
156+
153157
// Retrieve the list of all packages underneath the current workspace
154158
// folder. Note that if the workspace folder is not the root of a Bazel
155159
// workspace but is instead a folder underneath it, we query for *only* the

0 commit comments

Comments
 (0)