It might be useful to have a variable that resolves to the current file's workspace directory (in contrast to ${workspaceFolder}, that resolves to the launch/task configuration's workspace folder).
This would make it easier to share launch and task configurations among all workspaces of a multi root workspace.
The variable could for example be called ${workspaceFolder:file} or ${fileWorkspaceFolder}.
Consider a multi root workspace for PowerShell development with the following folders/files:
Common \ .vscode \ tasks.json
Module_A \ Source \ My_Script.ps1
Module_B \ Source \ Main \ Another_Script.ps1
When I run a task from the 'Common' workspace on the My_Script.ps1 file, ${workspaceFolder} resolves to Common\ and there is no (automatic) way to access the files's workspace folder Module_A\.
This is a fair feature request, however we do not have it on our immediate plan. Thus assigning to backlog and we might add this in the future. Thanks
Maybe @alexr00 is open for a PR to tackle this...
Just to elaborate on the use case and as reference for other users trying to achieve similar workflows:
I resorted to manually copying the task.json and launch.json files into each individual workspace, expecting each workspace to use their respective task/launch configuration. Turns out this is not how multi-root workspaces work at all.
You have to manually select the correct debug configuration each time you switch to another workspace. Similar situation for tasks: Running the default test task will prompt you to select the desired workspace (if you have one default test task in each workspace) and when you run a task by name via hotkey (and have a task with that name in each workspace), the task from the first workspace will be ran.
Conclusion: This obviously is not the intended use case for multi-root workspaces; you are better off using individual single-root workspaces (with replicated configurations) for now.
I would be open to a PR for this.
/duplicate #84162
Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.
Happy Coding!
With #84162 a new variable ${fileWorkspaceFolder} has been introduced.
Most helpful comment
With #84162 a new variable
${fileWorkspaceFolder}has been introduced.