mariniou77
mariniou77

Reputation: 37

How to enable the configuration settings at my extension for Visual studio code (vscode.workspace.getConfiguration())

I am writing a Visual Studio Code extension and I want to enable the configuration settings of my extension in order to give the opportunity to the user to configure some general settings for the extension.  I want to have the name of my extension here at the extension settings

I added at my package.json these lines for the beginning

"contributes": {
    "configuration": {
      "title": "Just a title"
    }, 
...

and at the extension.ts these:

const extensionPath = context.extensionPath;
let settingsConfig = vscode.workspace.getConfiguration('myextension name');
    
settingsConfig.get('myextension name', extensionPath);

but it doesn't work. In the Visual Studio Documentation, the only thing mentioned for calling the configuration settings is this: You can read these values from your extension using vscode.workspace.getConfiguration('myExtension')

Thank you in advance.

Upvotes: 1

Views: 853

Answers (1)

notexactly
notexactly

Reputation: 1018

The package.json configuration you provided does not seem to be correct. I have provided a short example below, that you can use to update your configuration in a similar way, where I am adding the boolean setting "mysetting".

"configuration": {
    "title": "Just a title",
    "properties": {
        "myextensionname.mysetting": {
            "type": "boolean",
            "default": "false",
            "description": "This does something"
        }
    }
}

Then, you can access the setting like this:

const mySetting = vscode.workspace.getConfiguration('myextensionname').mysetting;

Upvotes: 3

Related Questions