VSCode无法在保存时自动格式化

时间:2019-08-12 09:35:47

标签: visual-studio-code autopep8

Vscode不会在保存时格式化我的代码。

我的vscode版本是:

  • Vscode 1.37.0(作为Bug射击的一部分进行了更新,不确定以前的版本,但这也不起作用)
  • autopep8 1.4.4(pycodestyle:2.5.0)

我的settings.json看起来像这样:

{
    "editor.detectIndentation": false,
    "editor.formatOnSave": true,
    "editor.insertSpaces": true,
    "editor.tabSize": 4,
    "python.formatting.autopep8Args": [
        "--max-line-length=120"
    ],
    "python.formatting.provider": "autopep8",
    "python.linting.enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.pep8Args": [
        "--max-line-length=120"
    ],
    "python.linting.pep8Enabled": true,
    "python.linting.pylintEnabled": false,
    "python.pythonPath": "/home/me/.python_virtualenvs/somepath"
}

为什么保存时自动格式化无法正常工作?

其他说明:

  • 这正确格式化了我的文件:python -m autopep8 --max-line-length 120 --in-place --aggressive --aggressive my_dirty_code.py
  • 保存后,我会在任务栏中看到Formatting with autopep8

1 个答案:

答案 0 :(得分:0)

尝试增加Format on Save Timeout中的Text Editor -> Formatting。 例如,将其设置为2000ms。