【问题标题】:VS Code and Python, isort doesn't do its jobVS Code 和 Python,isort 没有做好它的工作
【发布时间】:2020-11-23 21:33:32
【问题描述】:

我已经安装了 blackisort 用于 VS Code 中的代码格式化。 黑色有效,而isort 似乎无效。

如果我从命令行运行isort 没有问题。

我尝试修改 setting.json 无济于事。这是最新版本:

{
    "window.zoomLevel": 0,
    /** "editor.codeActionsOnSave": null */
    /** Enable format on save */
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        /** Pyformat use it's own code action to prevent confliction with other tools. */
        "source.organizeImports.pyformat": true,
        "source.organizeImports.python": true
    },
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.languageServer": "Pylance",
    /** "python.sortImports.path": "isort", */
    "python.sortImports.args": [
        "-m 3",
        "-tc",
        "-w 88"
    ],
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--line-length=88"
    ],
...

有什么建议吗?

【问题讨论】:

    标签: python visual-studio-code settings isort


    【解决方案1】:

    VS Code 一次只支持使用一个格式化程序。但是,this 回答中描述了一种解决方法:

    const firstFormatter = commands.executeCommand('editor.action.formatDocument');
    
    firstFormatter.then(() => myFormat());
    

    我会亲自将其配置为使用黑色,然后附加命令以运行第二个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 2013-10-10
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      相关资源
      最近更新 更多