VS Code: Use the list of multi-root workspace folders during dev container build

Viewed 416

I have a ~/projects/ directory with a bunch of cloned Git repos in it. I like to select subsets of these and save them as VS Code multi-root workspaces as ~/projects/*.code-workspace.

I also use a dev container, configured with ~/projects/.devcontainer.json so that all the workspaces find it automatically.

When I build a dev container, I would love to be able to run some initialization logic with the input being the list of folders in the open workspace.

I can use ${containerWorkspaceFolder} in .devcontainer.json, but this gives me ~/projects, not the exact .code-workspace file, and there are multiple .code-workspace files in the directory. If I could get the path of the current .code-workspace file, I could parse the json and get the folder list, but it seems I can only get the parent folder.

I tried setting terminal.integrated.env.linux in foo.code-workspace to set a per-workspace environment variable CODE_WORKSPACE_FILE=~/projects/foo.code-workspace, but it isn't visible to the devcontainer build, only in integrated terminals I open after the workspace is already open in the container.

I see that there is a workspace.workspaceFolders() method in the vscode extension API. I don't want to write an extension just to expose that value to the devcontainers system, but maybe that's the only way currently.

Any other ideas?

0 Answers
Related