Enable fix/formatting commands for Python and Jupyter Notebook files only#487
Enable fix/formatting commands for Python and Jupyter Notebook files only#487snowsignal wants to merge 1 commit intomainfrom
Conversation
dhruvmanila
left a comment
There was a problem hiding this comment.
It might be worth looking at how ESLint does it as it doesn't raise any error if we run the "ESLint: fix all" command in settings.json.
MichaReiser
left a comment
There was a problem hiding this comment.
I don't think this works for untitled documents or files that use custom extensions but are associated with the python language.
| "when": "resourceExtname == .py || resourceExtname == .pyi || resourceExtname == .ipynb" | ||
| }, | ||
| { | ||
| "command": "ruff.executeFormat", | ||
| "when": "resourceExtname == .py || resourceExtname == .pyi || resourceExtname == .ipynb" | ||
| }, | ||
| { | ||
| "command": "ruff.executeOrganizeImports", | ||
| "when": "resourceExtname == .py || resourceExtname == .pyi || resourceExtname == .ipynb" |
There was a problem hiding this comment.
Hmm, I don't think we can do that. You can configure ruff to lint files with arbitrary extensions using extend-include. These files would no longer be linted. It also means that auto fix would no longer run on any new/untitled files because they don't have an extension yet (they only have an associated language that we should probably use in the LSP).
There was a problem hiding this comment.
You're right, this wouldn't work with arbitrary file extensions.
I might try using @dhruvmanila's suggestion and just handle the snapshot not available error more gracefully in ruff server.
Summary
Fixes astral-sh/ruff#11744.
The extension would allow commands like
ruff.applyAutofixto run on any file, even non-Python files. This PR adds a command palette filter so that these commands only appear in the palette when working with Python or Jupyter Notebook files.Test Plan
Ensure that commands like
Ruff: Fix all auto-fixable problemsstill appear in the command palette (Ctrl/Cmd + Shift + P) for files with the following extensions:*.py*.pyi*.ipynbThen, ensure that these commands do not appear for other kinds of files (for example:
*.tomlor*.json).Ruff: Restart servershould still be available.