vscode-ruff
vscode-ruff copied to clipboard
Order Ruff disable suggestions
Is it possible to position the "Disable for this line" action after other substantive quick fixes? In the screenshot below, you can see that I can fix the missing import error by importing the os module, but that option is listed after the disable option. However, I generally treat disabling type checking or linting errors like this as a measure of last resort, and it would be nice if its order of appearance reflected that. This would also reduce the number of keyboard movements required to reach substantive fixes.
This seems like a good idea to me, but I'm not sure if we have control over these suggestions, at least in this case. When I try this in VS Code, where I only have Ruff and no other Python extensions enabled, I only see the first suggestion. I think Add "import os" and the others are coming from a different extension.
We could consider setting isPreferred to false for the disable actions:
/**
* Marks this as a preferred action. Preferred actions are used by the
* `auto fix` command and can be targeted by keybindings.
*
* A quick fix should be marked preferred if it properly addresses the
* underlying error. A refactoring should be marked preferred if it is the
* most reasonable choice of actions to take.
*
* @since 3.15.0
*/
isPreferred?: boolean;
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeAction
Surprisingly, setting isPreferred to false doesn't seem to help. Not sure if pylance sets isPreferred for the add import action
In general, I don't think the server only has the control of the code actions provided by the server itself but not of other servers. If there are multiple language servers running, the client will be ordering the code actions according to it's own logic.
Related: https://github.com/astral-sh/ruff-vscode/issues/624, https://github.com/microsoft/pylance-release/issues/7018, https://github.com/astral-sh/ruff/issues/12279
As mentioned by Brent, code actions provided by Ruff will be prefixed with "Ruff:", so the code actions that you're seeing in the editor which aren't prefixed with "Ruff:" are not provided by Ruff.