gpt4 book ai didi

visual-studio-code - 如何使用扩展包更新 vscode 中的用户 settings.json?

转载 作者:行者123 更新时间:2023-12-04 08:39:36 25 4
gpt4 key购买 nike

我开发了一个 vscode extension VSCodeWebDeveloperExperiencePack , 现在我正面临其中一些之间的冲突,例如 turbo consoledeploy ,我在扩展页面上写了一个配置手册,如下所示:
您可能想要使用的预定义设置:

  • ctrl+shift+p
  • 类型 settings
  • 点击 Prefrences: Open settings (JSON)打开您的 settings.json 文件
  • 添加这些设置行:

  •   "workbench.iconTheme": "material-icon-theme",
    "workbench.colorTheme": "Atom One Dark",
    "files.autoSave": "afterDelay",
    "editor.fontFamily": "Fira Code",
    "editor.fontLigatures": "",
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.fontSize": 16,
    "window.zoomLevel": 1,
    "sync.gist": "70a5fe700fe4e46aebdf678a5c1db398",
    "typescript.preferences.importModuleSpecifier": "non-relative",
    "local-history.exclude": [
    "**/.history/**",
    "**/.vscode/**",
    "**/node_modules/**",
    "**/typings/**",
    "**/out/**",
    "**/Code/User/**"
    ]
    另外,还有一些 keybindings配置如下:
    [
    {
    "key": "ctrl+shift+alt+l",
    "command": "bookmarks.jumpToNext",
    "when": "editorTextFocus"
    },
    {
    "key": "ctrl+alt+l",
    "command": "-bookmarks.jumpToNext",
    "when": "editorTextFocus"
    },
    {
    "key": "ctrl+shift+alt+k",
    "command": "extension.deploy.listen"
    },
    {
    "key": "ctrl+alt+l",
    "command": "-extension.deploy.listen"
    }
    ]
    但我想让它成为可能或向用户展示选择 configure automatically 的选择,单击它或安装扩展程序,它将所需的配置放入用户的 settings.json。
    我读了 VScode ,但无法解决问题,例如我确实将它添加到我的 ext-pack package.json :
      "contributes": {
    "configuration": {
    "title": "VsCode Web Developer Experience",
    "properties": {
    "editor.fontSize": {
    "type": "number",
    "default": 22,
    "description": "this will changes the font settings"
    }
    }
    }
    }

    最佳答案

    我已经根据 vscode 文档解决了这个问题,这里有一个你可以使用的例子:

  • 把这个放在 package.json zpack-package.json :
  •  "contributes": {
    "commands": [
    {
    "command": "zpack.updateConfig",
    "title": "Update Essentials Web Extension Pack (ZPack series) Config"
    }
    ]
    },
  • 使用它来触发操作 zpack-extension.ts :

  • import * as vscode from "vscode";
    import { extractAsKeyValue, GeneralObject } from "./util";
    import { defaultSettings } from "./defaultSettings";

    const updateUserSettings = async (settings: GeneralObject[]) => {
    settings.forEach(async setting => {
    const { key, value } = extractAsKeyValue(setting);
    await vscode.workspace
    .getConfiguration()
    .update(key, value, vscode.ConfigurationTarget.Global);
    });
    };
    export async function activate(context: vscode.ExtensionContext) {
    console.log(
    'Congratulations, your extension "Essentials Web Extension Pack (ZPack series)" is now active!'
    );
    let disposable = vscode.commands.registerCommand(
    "zpack.updateConfig",
    async () => {
    console.log(JSON.stringify(defaultSettings, null, 1));
    await updateUserSettings(defaultSettings);
    await vscode.window.showInformationMessage(
    "ZPack Config has been updated"
    );
    }
    );
    context.subscriptions.push(disposable);
    }

    export function deactivate() {}

    关于visual-studio-code - 如何使用扩展包更新 vscode 中的用户 settings.json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64628565/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com