Search code examples
visual-studio-codevscode-extensions

Write initial settings to settings.json


I am looking for a way to write initial settings to settings.json for when my extension is installed.

I found WorkspaceConfiguration API, but that seems to retrieving/updating values at runtime.

I'm looking to get my settings + comments into the default settings file

e.g. How TSLint does it: enter image description here


Solution

  • I hope I get your question correctly: I assume you mean the User Settings settings.json you can get via File>Preferences>User Settings.

    If you know that TSLint does it, you can go to your extensions folder (windows: $USERFOLDER/.vscode/extensions), pick the extension (in my case it was the folder "eg2.tslint-0.6.7") and peek the files.

    ...
    "contributes": {
        "configuration": {
            "type": "object",
            "title": "TSLint",
            "properties": {
                "tslint.enable": {
                    "type": "boolean",
                    "default": true,
                    "description": "Control whether tslint is enabled for TypeScript files or not."
                },
                "tslint.rulesDirectory": {
                    "type": [
                        "string",
                        "array"
                    ],
                    "items": {
                        "type": "string"
                    },
                    "description": "An additional rules directory",
                    "default": ""
                },
                "tslint.validateWithDefaultConfig": {
                    "type": "boolean",
                    "description": "Validate a file when there is only a default tslint configuration is found",
                    "default": false
                },
                "tslint.configFile": {
                    "type": "string",
                    "description": "The path to the rules configuration file",
                    "default": ""
                },
                "tslint.ignoreDefinitionFiles": {
                    "type": "boolean",
                    "default": true,
                    "description": "Control if TypeScript definition files should be ignored"
                },
                "tslint.exclude": {
                    "type": [
                        "string",
                        "array"
                    ],
                    "items": {
                        "type": "string"
                    },
                    "description": "Configure glob patterns of file paths to exclude from linting"
                },
                "tslint.run": {
                    "type": "string",
                    "enum": [
                        "onSave",
                        "onType"
                    ],
                    "default": "onType",
                    "description": "Run the linter on save (onSave) or on type (onType)"
                },
                "tslint.nodePath": {
                    "type": "string",
                    "default": "",
                    "description": "A path added to NODE_PATH when resolving the tslint module."
                },
                "tslint.autoFixOnSave": {
                    "type": "boolean",
                    "default": false,
                    "description": "Turns auto fix on save on or off."
                }
            }
        }
    ...
    

    Hope this helps