I am setting a configPath context variable using...
const configPath = '/some/file/path.yml';
vscode.commands.executeCommand(
'setContext',
'ext.configPath',
configPath
);
... which can be used within when properties in package.json. For example, "when": "ext.configPath".
I cannot seem to obtain the value for string interpolation, or programmatically.
I would like to know...
{
"id": "ext.treedata.accounts",
"name": "Accounts - ${context:ext.configPath}",
"when": "ext.configPath"
}
... I would expect the title to read Accounts - /some/file/path.yml.
const configPath = vscode.getContext('ext.configPath');
console.log(configPath); // Outputs: /some/file/path.yml
I've tried using ${context:ext.configPath} to interpolate, and I've tried looking for getContext methods. I've also tried searching the vscode extension development docs.
There is no getContext API/command, unfortunately. There is however, an open issue (https://github.com/microsoft/vscode/issues/10471), but no ETA.
So, in your case, you will have to store that value somewhere. Depending on your scenarios, maybe you could take advantage of workspaceState or globalState Mementos.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With