【发布时间】:2021-02-06 13:38:08
【问题描述】:
我的 Django 项目在 VSCODE 中有以下工作区设置。
{
"folders": [
{
"path": "."
}
],
"settings": {
"python.pythonPath": "/Users/kim/.pyenv/versions/3.7.7/bin/python3.7",
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"editor.tabSize": 4,
"[javascript]": {
"editor.tabSize": 2
},
"[json]": {
"editor.tabSize": 2
},
"[markdown]": {
"editor.tabSize": 2
},
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": true,
"python.linting.flake8Enabled": true,
"python.linting.pylintArgs": ["--enable=unused-import", "--enable=W0614"],
"python.formatting.provider": "black",
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"workbench.iconTheme": "vscode-icons",
"editor.formatOnSave": true
}
}
当我按下 Cmd+S 保存文件时,您可以看到它是如何闪烁的。来自这个gif
为什么会出现这种闪烁?如果它发生一次,我可以理解。但它会来回闪烁。好像 vscode 在两种不同的格式之间保存时格式化,无法下定决心。
我该如何正确解决这个问题?
【问题讨论】:
-
你的 VS Code 版本是多少?您是否检查过“输出”>“Python”选项卡中是否有任何“奇怪”的消息? AFAIK,只有黑色对 formatOnSave 有影响,而 flake8 结果应该只出现在“问题”选项卡中(因为它是一个 linter,而不是一个格式化程序)。
-
解决了。您可以在此处查看 github 链接以了解原因和建议的解决方案 github.com/microsoft/vscode-python/issues/…
标签: python-3.x visual-studio-code vscode-settings