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

organizeImports buggy in vscode

HenrikZabel opened this issue · comments

When using "editor.codeActionsOnSave": { "source.organizeImports": true } my whole code jumps in vscode.

Python version: 3.11.4
Ruff version: v2024.0.0
OS: Windows 10 Home

@HenrikZabel could you provide a bit more detail about the behavior you're seeing and the behavior you'd prefer?

Closing for now, can always re-open if we receive more info.

I am sorry for the delay:

Basically, the whole code always "jumps" when I save my file. It seems that Ruff needs a relatively long time to sort the imports. Also, the imports are sorted when I save once and then when I save again, all the imports are totally mixed up. Especially when I have many imports from a library, I notice that Ruff takes a relatively long time. Example:

from .serializers import (
    AccountSerializer,
    EmailSerializer,
    NameSerializer,
    RegistrationSerializer,
    UsernameSerializer,
)

If I then immediately save the file again, it looks like this:

from .serializers import (AccountSerializer, EmailSerializer, NameSerializer, RegistrationSerializer, UsernameSerializer)

Is it possible that you have some other extension that's interfering? Ruff wouldn't sort imports in that style, it doesn't even support it.

I completely reinstalled Python and now the problem is gone. So I think the problem was actually not with Ruff, but with something else. I apologize

Oh that's great!