【发布时间】:2020-09-15 19:45:22
【问题描述】:
我使用 排序 HTML 和 Jade 属性 扩展,它提供命令 attrsSorter.execute。我想设置我的工作区 settings.json 以便“editor.codeActionsOnSave”部分每次在保存之前运行它,然后格式化 / linting 以便我们获得排序的好处。
查看了所有地方,无法弄清楚每次执行保存时如何简单地执行此操作。感谢您的帮助!
【问题讨论】:
我使用 排序 HTML 和 Jade 属性 扩展,它提供命令 attrsSorter.execute。我想设置我的工作区 settings.json 以便“editor.codeActionsOnSave”部分每次在保存之前运行它,然后格式化 / linting 以便我们获得排序的好处。
查看了所有地方,无法弄清楚每次执行保存时如何简单地执行此操作。感谢您的帮助!
【问题讨论】:
我浪费了太多时间来弄清楚如何运行由this plugin 定义的命令test-explorer.run-all。如果你用editor.codeActionsOnSave 替换下面的test-explorer.run-all,我认为应该可以。
我一起破解的是首先安装Trigger Task on Save extension 它不是按照其他答案的 bash 命令,而是在保存时运行 VS 代码任务。
根据the VS code docs 然后,您可以定义一个自定义任务来包装命令。对我来说,这看起来像
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "mocha-explorer",
"command": "${command:test-explorer.run-all}",
}
]
}
这里mocha-explorer 是我自己的任意标签。
最后,配置settings.json 文件以在保存时按其标签运行您的任务,对我来说,这看起来像:
"triggerTaskOnSave.tasks": {
"mocha-explorer": ["*.js"]
}
我是所有这些 VS 代码配置的新手,但我希望对某人有所帮助。
可能对更复杂的任务有帮助的相关有用答案:Is there a way to run a command with VS Code tasks?
【讨论】:
【讨论】: