Feat/manual workspace path#625
Conversation
Add a new configuration option `bazel.workspacePath` that allows users to manually specify the Bazel workspace directory path. This is useful when: - Working with multiple MODULE.bazel files in nested directories - The auto-detection picks the wrong workspace root - Using local_path_override with multiple repositories The path can be absolute or relative to the VS Code workspace folder. Fixes bazel-contrib#621
…onfig Add tests to verify: - Auto-detection works when workspacePath is not configured - Configured absolute path is used correctly - Configured relative path is resolved correctly - Invalid configured path falls back to auto-detection - Configured path takes precedence over nested MODULE.bazel
|
We recently merged #608. Might this maybe already be enough to fix your problem? It at least should enable you to open a subdirectory of a Bazel workspace and have the queries run from the root of it. As I am generally against adding to many config options I would like to understand your usecase better. What is the motivation for opening just a subdirectory of a workspace instead of the true root? |
I don't think it helps for the linked issues #621 and #472. The problem here is that we have multiple MODULE.bazel files and we run all queries from the nearest MODULE.bazel file. But there exists project setups, where only the root MODULE.bazel file contains all the resolved paths and therefore every query must be run from the root folder. The PR you mentioned is only able to find the MODULE.bzl file if we have only a subfolder open. |
|
I do think this is a reasonable request, although I would be inclined to make it an array, like the There was a previous discussion on how to automatically fix the situation you're encountering in a slack thread a while ago, but doing this correctly is tricky so a config option sounds better here. |
|
I tested the changes on my windows machine and it picks up the correct path. However, currently not all queries are executed from bazel root folder. For example the go to definition query uses the current document as working directory. vscode-bazel/src/definition/bazel_goto_definition_provider.ts Lines 80 to 101 in 759d208 I assume this is simply a bug and we should use |
|
Any updates on this one? |
|
@cbandera @cameron-martin |
Summary
Add a new configuration option
bazel.workspacePaththat allows users to manually specify the Bazel workspace directory path.Problem
Fixes #621
Fixes #472
When working with multiple
MODULE.bazelfiles in nested directories (e.g., monorepo setups withlocal_path_override), the extension picks the nearest workspace file instead of the intended root workspace. This causes queries to fail because they run in the wrong directory.This is especially useful when opening a subdirectory of the Bazel workspace in VS Code, where the root
MODULE.bazel/WORKSPACEfile is located in a parent directory outside the opened folder.Related: #428
Solution
Added a new configuration option
bazel.workspacePaththat:Usage
{ "bazel.workspacePath": "/absolute/path/to/workspace" }