vscode-bazel
vscode-bazel copied to clipboard
Support ${workspaceFolder} in buildifier & bazel paths
I can add a bazel path relative to the vscode workspace root, but I can't do the same for a buildifier path.
Here's the buildifier path code which is not relative to the workspace root: https://github.com/bazelbuild/vscode-bazel/blob/d2e0b7dd9f387ee66829e960b2016dba474b2df8/src/buildifier/buildifier_availability.ts#L33
Here's the bazel path code which is relative to the workspace root: https://github.com/bazelbuild/vscode-bazel/blob/8fbcd2769228731827c4b7c2ba3bbc36bb1f5e34/src/bazel/tasks.ts#L72
These should obviously use the same code and both should support paths relative to the workspace root :)
Note: most other vscode extensions support putting ${workspaceRoot} in the path to refer to the vscode workspace root. For example, clangd, protoc, shellcheck, and python all do this, and I'm sure many more.
So the bazel one happens to work as relative to the bazel workspace root, not the VSCode root; they may or may not be the same.
You can have a VSCode workspace with two (or more) folders, and they can map to different bazel workspaces; so a relative path likely wouldn't work for you in that case (unless you have a copy in the same relative position to each root).
The bazel commands have to be invoked with a CWD within the bazel workspace, so that's why the working directory gets set and sorta ends up working out. If you opened a sub folder of a bazel workspace, relative paths might work, but it wouldn't be relative to the "root" might expect via what VSCode is set to.
Anyway, to make everything work relative, we'd have to compute the real path ourselves, but even doing that, what do we do for a VSCode workspace with multiple folders open, which one would we assume is the root to allow things to be relative too?
It's extremely common for extensions to support either relative paths from the workspace root or something like $workspace_root... so, do whatever they do? Perhaps just where the workspace file actually is?
I believe by workspace root, OP means the folder at ${wokspaceFolder} which is VS Code’s workspace, of which there’s only ever one open.
More info here: https://code.visualstudio.com/docs/editor/variables-reference
I believe by workspace root, OP means the folder at
${wokspaceFolder}which is VS Code’s workspace, of which there’s only ever one open.More info here: https://code.visualstudio.com/docs/editor/variables-reference
Correct, I'll clarify that. Didn't realize it would be confusing with bazel's "workspace"
Is there a solution here that doesn't require absolute paths for only the buildifier binary?
In case it's not clear, we have to have settings like:
{
"bazel.buildifierExecutable": "/Users/some-user/some-arbitrary-path-to-the-repo/tools/buildifier",
"bazel.executable": "tools/bazel"
}
We can write the bazel.executable setting once and share it amongst a team, but we cannot write the bazel.buildifierExecutable setting once and share it amongst a team. The absolute path is almost never the same between different machines: platforms, users, personal preference, etc.
Instead, it would be ideal if we could use the same relative path support for buildifier that we can currently use for bazel:
{
"bazel.buildifierExecutable": "tools/buildifier",
"bazel.executable": "tools/bazel"
}
Duplicate of #132.