command-variable icon indicating copy to clipboard operation
command-variable copied to clipboard

workspaceFolder in a multi-root workspace

Open dyitzchaki-roku opened this issue 1 year ago • 3 comments

The value of ${workspaceFolder} is expanded differently by the extension than how VSCode expands it. Outside the extension,

It doesn't return the workspace folder the currently active file is in. It returns the workspace folder in which the task is defined https://github.com/Microsoft/vscode/issues/54596#issuecomment-406391812

Personally I find the way VSCode expands it is more useful. IMO it can also be used for resolving nested ${input} variables

The fact that I do not support the ${input} variable is that I don't know which .json is the source of the command (task, launch, keybindings). https://github.com/rioj7/command-variable/issues/45#issuecomment-1412581498

dyitzchaki-roku avatar Feb 09 '24 09:02 dyitzchaki-roku

@dyitzchaki-roku Like the comment from #45, I don't have the information that VSC has, VSC calls my command and I have no clue where it is called from. If you want the workspace folder where the task is defined you should use ${workspaceFolder:name}. Where name is the name of that workspace, as mentioned in the vscode issue 54596

rioj7 avatar Feb 10 '24 14:02 rioj7

Maybe workspaceFolder should be renamed to fileWorkspaceFolder then

${fileWorkspaceFolder} - the current opened file's workspace folder

https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables

dyitzchaki-roku avatar Feb 13 '24 22:02 dyitzchaki-roku

@dyitzchaki-roku I can add this new variable as a synonym, because I can't supply the behavior of VSC. I might make an educated guess by analyzing all tasks.json and launch.json files and try to find the input entry used. But the simple method is to also name the workspace in the task input var used. What to do with the global defined tasks, they are not part of a workspace.

rioj7 avatar Feb 14 '24 21:02 rioj7