astral-sh/ruff-vscode

ruff doesn't work when I rename'xxx.PY' to 'xxx.py'

Zander-1024 opened this issue · 10 comments

I have another file that says xxx.PY in the name. When I found the problem, I changed it to xxx.py. At this point I found that the format didn't work.
When I change the file name or the extension, I find that it can be formatted normally again.

However, when the file is modified to xxx.py, it does not take effect. Finally, I find that the URI still points to xxx.PY. However, when I modify the file to xxx.PY again, the file still cannot be formatted.

Is there a cache for this? When I restarted the computer, the problem persisted.

2024-08-07 16:21:04.415 [info] Params: {
    "textDocument": {
        "uri": "file:///d%3A/*/xxx.PY"
    }
}

Ruff v2024.36.0

Can you provide a way to reproduce this? The log message that you've provided is the request payload sent by VS Code.

When I change the file name or the extension, I find that it can be formatted normally again.

How are you running the formatter? And, how are you renaming the file? Is it from the command-line or by right-clicking the filename in VS Code and selecting the "Rename" option?

At least on Mac, VS Code seems to not care about whether it's uppercase or lowercase as I see that the payload always contains .py extension.

Can you provide a way to reproduce this? The log message that you've provided is the request payload sent by VS Code.

When I change the file name or the extension, I find that it can be formatted normally again.

How are you running the formatter? And, how are you renaming the file? Is it from the command-line or by right-clicking the filename in VS Code and selecting the "Rename" option?

At least on Mac, VS Code seems to not care about whether it's uppercase or lowercase as I see that the payload always contains .py extension.

system is windows10 , renaming is done by clicking on the file, when it's editable, formatting is done by right-clicking and selecting from the menu, and ruff turns on native server mode. I tried again, and as long as the suffix was written as PY and changed from PY to py, the file would have problems.

ruff-lsp doesn't seem to have this problem

system is windows10 , renaming is done by clicking on the file, when it's editable, formatting is done by right-clicking and selecting from the menu, and ruff turns on native server mode. I tried again, and as long as the suffix was written as PY and changed from PY to py, the file would have problems.

Is it possible for you to record a video doing this and send it? I'm not able to follow how is the renaming being done and which option is selected for the formatting. Can you also provide the verbose logs by setting "ruff.trace.server": "verbose"?

ruff_log.txt
The problem only occurs in native server mode, I switched computers and it's still happening!

Windows is case-insensitive, maybe related.

@Zander-1024 Have you changed the case-sensitivity setting for the file system? (https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity#modify-case-sensitivity).

I checked and it is disabled, maybe I need to turn it on. When I only change the case of the suffix, the uri doesn't change, so rust can't recognize the file properly, causing this problem! ruff-lsp doesn't have this problem because it doesn't read the file directly?

If it's disabled then foo.py == foo.PY should be true, I think.

Can you send me your VS Code settings? Do you see this happening in other Python extension like vscode-flake8 or vscode-black-formatter, etc.?

settings.json

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "venv",
	"test",
	"proto",
]

# Same as Black.
line-length = 120
indent-width = 4

extend-include = ["*.ipynb"]

# Assume Python 3.8
target-version = "py310"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
select = ["E", "F", "B"]
ignore = ["E501","B905"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"