VS Code 自动保存 afterDelay w/Prettier 不工作
VS Code auto save afterDelay w/Prettier not working
VS 代码版本:1.64.2
Prettier 扩展版本:9.2.0
我想要 Prettier 在自动保存时运行,应该每 500 毫秒运行一次。我的工作区中有以下内容 JSON:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"prettier.trailingComma": "all",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500
}
我的用户也一样 JSON:
{
"workbench.colorTheme": "Darcula",
"workbench.iconTheme": "material-icon-theme",
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.trailingComma": "all",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500
}
注意:这是两个 JSON 文件的全部内容。设置中没有列出其他格式化程序。
以及以下测试片段:
let = "blah"
但是什么也没有发生。该文件 - 之前已保存到文件系统 - 在 500 毫秒后未保存为当前状态,因此 Prettier 不是 运行.
我很茫然,如有任何帮助,我们将不胜感激。
编辑:手动保存(例如,ctrl
+ s
)有以下输出:
["INFO" - 8:27:41 PM] Formatting
file:///c%3A/Users/Kevin/Documents/Programming%20Stuff/JS/scratchpad.js
["INFO" - 8:27:41 PM] Using ignore file (if present) at
c:\Users\Kevin\Documents\Programming Stuff\JS.prettierignore ["INFO"
- 8:27:41 PM] File Info: { "ignored": false, "inferredParser": "babel" } ["INFO" - 8:27:41 PM] No local configuration (i.e.
.prettierrc or .editorconfig) detected, falling back to VS Code
configuration ["INFO" - 8:27:41 PM] Prettier Options: {
"arrowParens": "always", "bracketSpacing": true, "endOfLine":
"lf", "htmlWhitespaceSensitivity": "css", "insertPragma": false,
"jsxBracketSameLine": false, "jsxSingleQuote": false,
"printWidth": 80, "proseWrap": "preserve", "quoteProps":
"as-needed", "requirePragma": false, "semi": true,
"singleQuote": false, "tabWidth": 2, "trailingComma": "all",
"useTabs": false, "vueIndentScriptAndStyle": false, "filepath":
"c:\Users\Kevin\Documents\Programming Stuff\JS\scratchpad.js",
"parser": "babel" } ["INFO" - 8:27:41 PM] Formatting completed in
0.069ms.
没有错误
Going by , the editor cannot format on save when the afterDelay
option is selected.它必须是 onFocusChange
或 onWindowChange
.
例如,用户级别 JSON 文件看起来像这样就可以了。当焦点离开编辑器时(例如,单击另一个打开的文件),它将自动保存文件并设置格式:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.autoSave": "onFocusChange",
}
VS 代码版本:1.64.2
Prettier 扩展版本:9.2.0
我想要 Prettier 在自动保存时运行,应该每 500 毫秒运行一次。我的工作区中有以下内容 JSON:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
},
"prettier.trailingComma": "all",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500
}
我的用户也一样 JSON:
{
"workbench.colorTheme": "Darcula",
"workbench.iconTheme": "material-icon-theme",
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.trailingComma": "all",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500
}
注意:这是两个 JSON 文件的全部内容。设置中没有列出其他格式化程序。
以及以下测试片段:
let = "blah"
但是什么也没有发生。该文件 - 之前已保存到文件系统 - 在 500 毫秒后未保存为当前状态,因此 Prettier 不是 运行.
我很茫然,如有任何帮助,我们将不胜感激。
编辑:手动保存(例如,ctrl
+ s
)有以下输出:
["INFO" - 8:27:41 PM] Formatting file:///c%3A/Users/Kevin/Documents/Programming%20Stuff/JS/scratchpad.js ["INFO" - 8:27:41 PM] Using ignore file (if present) at c:\Users\Kevin\Documents\Programming Stuff\JS.prettierignore ["INFO"
- 8:27:41 PM] File Info: { "ignored": false, "inferredParser": "babel" } ["INFO" - 8:27:41 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, falling back to VS Code configuration ["INFO" - 8:27:41 PM] Prettier Options: {
"arrowParens": "always", "bracketSpacing": true, "endOfLine": "lf", "htmlWhitespaceSensitivity": "css", "insertPragma": false,
"jsxBracketSameLine": false, "jsxSingleQuote": false,
"printWidth": 80, "proseWrap": "preserve", "quoteProps": "as-needed", "requirePragma": false, "semi": true,
"singleQuote": false, "tabWidth": 2, "trailingComma": "all",
"useTabs": false, "vueIndentScriptAndStyle": false, "filepath": "c:\Users\Kevin\Documents\Programming Stuff\JS\scratchpad.js",
"parser": "babel" } ["INFO" - 8:27:41 PM] Formatting completed in 0.069ms.
没有错误
Going by afterDelay
option is selected.它必须是 onFocusChange
或 onWindowChange
.
例如,用户级别 JSON 文件看起来像这样就可以了。当焦点离开编辑器时(例如,单击另一个打开的文件),它将自动保存文件并设置格式:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": null,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.autoSave": "onFocusChange",
}