vscode-ruff icon indicating copy to clipboard operation
vscode-ruff copied to clipboard

Order Ruff disable suggestions

Open msmoiz-biq opened this issue 5 months ago • 5 comments

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.

Image

msmoiz-biq avatar Jun 17 '25 20:06 msmoiz-biq

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.

ntBre avatar Jun 17 '25 21:06 ntBre

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

MichaReiser avatar Jun 18 '25 08:06 MichaReiser

Surprisingly, setting isPreferred to false doesn't seem to help. Not sure if pylance sets isPreferred for the add import action

MichaReiser avatar Jun 18 '25 08:06 MichaReiser

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

dhruvmanila avatar Jun 18 '25 09:06 dhruvmanila

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.

dhruvmanila avatar Jun 18 '25 09:06 dhruvmanila