我可以在 "Format Document" 上执行指定任务吗?

Can I execute a specified task on "Format Document"?

我正在使用自定义脚本来格式化我的代码。目前,每当我想格式化时,我都必须调用 Tasks: Run Task 然后选择我的格式化任务。

是否可以让 Format Document 执行我的任务?

这很好,因为它可以让我在保存时自动编队。

关于我的VSCode:

Version: 1.44.2
Commit: ff915844119ce9485abfe8aa9076ec76b5300ddd
Date: 2020-04-16T17:50:03.709Z
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.15.0-96-generic snap

我还没有使用实际的格式化程序对其进行测试,但您可以从键绑定调用任务。尝试

{
  "key": "shift+alt+f",
  "command": "-editor.action.formatDocument",
  "when": "editorHasDocumentFormattingProvider && editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly"
},

{
  "key": "shift+alt+f",         // or whatever keybinding you wish
  "command": "workbench.action.tasks.runTask",
  "args": "your format task label here"
},

我使用了默认的 Format Document 键绑定,但您可以使用任何您想要的键绑定。