Open DanCardin opened 1 month ago
Thanks for opening this feature request, @DanCardin!
I do think this would a setting worth exploring for editors that don't have a way to run code actions / commands on save.
I'd love for there to be a ruff server-specific setting that optionally enables either/or both of organizeImports or fixAll actions on lsp format.
Just to clarify - are you also proposing that we introduce a separate setting to enable running organizeImports
/ fixAll
when we format?
Per my parenthesis block in the OP, i'd personally be happy with an organizeImportsOnFormat = true
or onFormat = {organizeImports = true}}
or whatever server setting (separate from the normal project-specific ruff config).
But with that said, I could imagine (by looking at https://github.com/astral-sh/ruff-lsp/issues/335) that someone might also want to enable fixAll
on save too. They're essentially the same feature request. i'm just not personally invested in having both.
Okay, thanks for clarifying 👍
Another usecase at here is you always trigger format action manually and you didn't set code actions on save. I usually organize imports, format, and fix violations after I complemented the source of target module. Currently I most use 3 actions each time I finished coding, it'd be nice to have three into one command.
Editor settings:
{
"ruff.format.action": {
"fix": true,
"isort": true,
"style": true,
}
}
style
enabled.Format Document
will respect these settings, Format Selection
ignores these settings.ruff.organizeImports
and/or ruff.fixAll
editor settings are disabled, revealment enabled options don't have affect in format actions.isort > fix > style
. We could have separated settings for prioritization, but I think this is good default for now.The Ruff CLI needs further discussion around new command (e.g. ruff action --fix --isort--no-style
).
Also, see this most-wanted feature request: https://github.com/astral-sh/ruff/issues/8232
In the PR for adding the organizeImports code action, i saw a reference to:
which, as far as i can tell, is a VSCode specific thing. Per https://github.com/astral-sh/ruff-lsp/issues/409 or https://github.com/astral-sh/ruff-lsp/issues/335, I'd love for there to be a
ruff server
-specific setting that optionally enables either/or both oforganizeImports
orfixAll
actions on lsp format.Personally, I'd likely enable just the
organizeImports
on save (which i see no reason ever to not run, which is why i'd rather have it automatic than a code action i need to remember to perform), perhaps not fixAll.