Search code examples
visual-studio-codevscode-extensions

How do I use path the to my VS Code extension's directory in a contributed setting's default value?


I am developing a VS Code extension for Vale style linting. It includes a styles sub-directory with files for individual style rules. Inside the extension, I'm overriding a config option from another extension in its package.json file:

"contributes": {
    "configurationDefaults": {
        "vale.valeCLI.config": ".vale.ini"
    }
 }

The .vale.ini file is included in the root directory of the extension itself. Is there a variable that points to the root directory of the current extension? Or a way derive it from an extension ID? The above code does not work for me...


Solution

  • I'm not aware of a variable for getting the path to an extension's installation directory in package.json.

    I'd take a different approach: let the default setting value be null, and then in your extension's code, if the value is null, then use the default path. You can create a helper function that gets the value of the setting, and then if the value is not null, return that value, and if it is null, return the extensionPath property of the Extension type. Everywhere you want to use that setting's value, call that helper function.