My Visual Studio Code extension relies on a workspace configuration. So, in extension test, I would like to set the workspace configuration, and then test if the extension works properly.
Extension contribution definition looks like this:
"contributes": {
"configuration": {
"properties": {
"assistant": {
"type": "object",
"properties": {
"modifiers": {
"type": "string",
"default": "g"
},
"rules": {
"type": "array",
"default": [],
"items": {
"properties": {
"regex": {
"type": "string"
},
"message": {
"type": "string"
},
"modifiers": {
"type": "string",
"default": "g"
}
}
}
}
}
}
}
}
},
An example configuration looks like this:
{
"folders": [
{
"path": "code"
}
],
"settings": {
"assistant": {
"rules": [
{
"regex": "^::ng-deep.*$",
"message": "Prepend with :host, so that styles won't leak",
"modifiers": "gm"
},...
When I call:
Among other approaches i tried:
const assistant = vscode.workspace.getConfiguration("settings");
assistant.update("assistant", "", ConfigurationTarget.Global).then(
(value) => {
console.log(assistant.get("assistant"));
},
(value) => {
console.log(value);
}
);
It returns the error:
Error: Unable to write to User Settings because settings.assistant is not a registered configuration.
I have tried also with ConfigurationTarget. Workspace, and various ways to access settings but nothing seem to work properly.
The extension seems to be installed properly in the test vscode application.
How to change vscode extension properties programmatically?