保存时我的vs代码会闪烁。我打开了 black 和 flake8 以及 formatonSave。为什么会闪烁?如何阻止它?

My vs code will flicker when I save. I turned on black and flake8 and formatonSave. Why does it flicker? How to stop it?

我在 VSCODE 中为我的 Django 项目设置了以下工作区设置。

{
    "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在两种不同格式之间保存时格式化,无法下定决心。

如何正确解决这个问题?

好的,我意识到我找到了问题和解决方案。

基本上问题是有两个格式化程序用于对导入进行排序。

我使用这个 github 评论中的答案

https://github.com/microsoft/vscode-python/issues/6933#issuecomment-543059396

        "[python]": {
            "editor.formatOnSave": true,
            "editor.codeActionsOnSave": {
                "source.organizeImports.python": true
            }
        },
        "python.formatting.blackArgs": ["--line-length", "88"],
        "python.sortImports.args": [
            "--multi-line=3",
            "--trailing-comma",
            "--force-grid-wrap=0",
            "--use-parentheses",
            "--line-width=88",
        ],

注意我将 organizeImports 更改为 organizeImports.python。 我还添加了一个 "python.formatting.blackArgs": ["--line-length", "88"]。这是为了和line-length保持一致。

同一问题在另一期中建议。我单独尝试过,但没有用。所以我将它与 sortImports args

结合起来