保存时运行扩展命令

Lar*_*dig 3 visual-studio-code

我使用Sorting HTML 和 Jade 属性扩展,它提供命令attrsSorter.execute。我想设置我的工作区 settings.json,以便“editor.codeActionsOnSave”部分每次在保存之前运行它,然后格式化/linting,以便我们获得排序的好处。

已经查看了所有地方,但无法弄清楚如何在每次执行保存时简单地执行此操作。感谢您的帮助!

dan*_*onn 5

我需要通过执行PostCSS Sorting 扩展来在保存时格式化 CSS 文件,我找到了本教程:Automatic CSS sorting in VS Code

根据它,你必须安装扩展: ryuta46.multi-command,然后修改 keybindings.json 文件。(F1 + 首选项:打开键盘快捷键 (JSON))

我的看起来像这样:

// Place your key bindings in this file to override the defaults
[
    {
        "key": "ctrl+s",
        "command": "extension.multiCommand.execute",
        "args": {
          "sequence": ["postcssSorting.execute", "workbench.action.files.save"]
        },
        "when": "editorLangId == css"
      }
]
Run Code Online (Sandbox Code Playgroud)

我希望它能帮助别人!:)