astral-sh/ruff-lsp

Formatting and "Fix All" doesn't work if it removes entire file content

dhruvmanila opened this issue · 2 comments

If you take the following code example in VSCode:

import os

And run the command Ruff: Fix all auto-fixable problems, nothing will happen.

But, suppose you add an additional statement:

import os

print("hello world")

Now, if you run the same command, it'll remove the import.

The reason it's not working in the first case is because we create a WorkspaceEdit only if the fixed source code isn't empty. But, in the first case it's going to be empty.

A new statement isn't even needed, just add some extra newlines and you'll be able to reproduce the bug.

(This change was reverted in #317)

Using astral-sh/ruff#8596, we can now safely write empty fixes on supported Ruff version.