将初始设置写入 settings.json

Write initial settings to settings.json

我正在寻找一种方法来将初始设置写入 settings.json,以便在安装我的扩展程序时使用。

我找到了 WorkspaceConfiguration API,但这似乎是 retrieving/updating 运行时的值。

我希望将我的设置和评论添加到默认设置文件中

例如TSLint 是如何做到的:

希望我能正确回答您的问题:我假设您指的是用户设置 settings.json 您可以通过文件>首选项>用户设置获得。

如果您知道 TSLint 会这样做,您可以转到您的扩展文件夹 (windows: $USERFOLDER/.vscode/extensions),选择扩展(在我的例子中是文件夹 "eg2.tslint-0.6.7") 并查看文件。

...
"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."
            }
        }
    }
...

希望对您有所帮助