astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling isort extension together with ruff

JakobThumm opened this issue · comments

I run into this error, where Ruff and isort both try to sort the imports, which for some reason leads to additional lines added to the end of the file.
Is there some way of checking if isort is enabled and print a warning?
Maybe even fix the error within the Ruff extension? I understand this error is mainly a vscode issue, but Microsoft doesn't seem to fix it soon.

I'm on Ubuntu 20.04. VSCode version 1.85.0, ruff version 0.1.6.
My settings.json looks like this:

 "python.defaultInterpreterPath": "/home/jakob/anaconda3/envs/stap",
    "ruff.format.args": ["--line-length", "120"],
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.fixAll": true,
            "source.organizeImports": true
        },
    }

Yeah, this bug is frustrating. Unfortunately, I don't know that there's much we can do... As an extension, the only way ((IUC) that we can see if another extension is installed is by marking it as a dependency (https://code.visualstudio.com/api/references/vscode-api#extensions). Alternatively, we could look at the virtual environment to see if isort is installed, but it's also legitimate to have isort installed in the environment but not use the two extensions in this problematic way.

I'm gonna merge into the existing issue, but I'm hoping it gets resolved by the VS Code team at some point.