You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When both Ruff and isort run on-save, last line of file is repeated #240
This may well be a Ruff problem but I'm having trouble understanding it, and it only occurs when both Ruff and isort are installed together, so I thought it was worth raising here.
When both Ruff and isort are installed, and configured to organize imports on save, the last line of the file ends up being repeated on-save.
Disabling either extension causes the file to format properly.
I think this has to do with the use of len(document.lines) to format the "whole file" edit, but I would've thought that the "versioned" edits would avoid this issue.
You might decide that this either (1) Ruff's problem, or (2) user error (given that you shouldn't really have two plugins organizing imports), but this does seem like unexpected behavior and possibly indicative of bug in either or both extension.
Reacted by q-wertz, Waldemar Villamayor-Venialbo, Matteo Renoldi, Hugo Hjertén, Alex Povel, Sergey Naumov, Jacob Østergaard Nielsen, takahashi-sdi, Matt Bell, Matěj Trnka and 3 more
My guess is that they're both generating the edit, and trying to apply it to lines 0-to-3 (or rather, start of line 0 to start of line 4). When the "second" formatter runs, the previous last-line is now on line 4, since we inserted a newline between the sys and setuptools imports. So we end up re-inserting that last line, rather than overwriting it.
This might actually be a VS Code bug. It should not be running both the import organizers. It should be running only one. The thing is I don't think we are even getting diferent versions here. I suspect we may be getting the same version.
Activity
karthiknadig commentedon Feb 13, 2023
Charlie Marsh (@charliermarsh) do both the extensions run the formatting? Can you share the logs from
isortand Ruff?FYI, In the next release of the python extension, we won't be installing
isort. Going forward, people will not have isort extension by default.charliermarsh commentedon Feb 13, 2023
Yeah I believe they both run.
I don't get much from the
isortlogs (I should probably clone it, run locally, and add more logging):I added some very verbose logging to
rufflocally:After the edit, if I hit Command + Z once, I get:
If I hit it again, I'm back to:
charliermarsh commentedon Feb 13, 2023
My guess is that they're both generating the edit, and trying to apply it to lines 0-to-3 (or rather, start of line 0 to start of line 4). When the "second" formatter runs, the previous last-line is now on line 4, since we inserted a newline between the
sysandsetuptoolsimports. So we end up re-inserting that last line, rather than overwriting it.karthiknadig commentedon Feb 13, 2023
This might actually be a VS Code bug. It should not be running both the import organizers. It should be running only one. The thing is I don't think we are even getting diferent versions here. I suspect we may be getting the same version.
karthiknadig commentedon Feb 13, 2023
Both get the same version:
This is Ruff

This is isort

karthiknadig commentedon Feb 14, 2023
Closing against microsoft/vscode#174295