微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决当我保存时,我的 vs 代码会闪烁我打开了 black and flake8 和 formatonSave为什么会闪烁?如何阻止它?

我在 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

enter image description here

为什么会出现这种闪烁?如果它发生一次,我可以理解。但它会来回闪烁。好像 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",],

注意我将组织导入更改为组织导入.python。 我还添加了一个 "python.formatting.blackArgs": ["--line-length","88"]。这是要与行长保持一致。

在另一个问题中提出了同样的问题。我单独尝试过,但没有用。所以我将它与 sortImports args 结合起来

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。