-
Notifications
You must be signed in to change notification settings - Fork 23
Run ruff format
when lsp formatting is invoked
#57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9207716
to
735b2d0
Compare
If ruff decided that |
This seems reasonable. I'll see if I can get this behavior in place unless anyone else wants to make an argument for the current approach (which always organizes imports) |
After a little more thinking I'm torn on the issue of whether or not to format imports by default. @JaRoSchm is clearly correct that So the question is whether to remain compatible with existing behavior of this plugin and always sort imports or to do the less surprising thing for ruff users and make import sorting opt-in (or maybe don't provide it at all?). I don't see a way that we can do both. @jhossbach do you have an opinion here? |
cb6bb60
to
077f739
Compare
So, if I understand astral-sh/ruff#8232 correctly the idea will be to have a command like |
20e4761
to
895e473
Compare
I believe this PR now has the behavior described - the second pass through the document will only occur if the I just want to make clear that users using python-lsp-ruff today are getting import sorting and are not getting code formatting. This PR inverts that behavior - users will get code formatting and will not (by default) get import sorting. IMO this is fine and would have to happen at some point but I want to draw attention to the change as there may be some confusion among users. |
1572254
to
23a3770
Compare
Adds the Subcommand enum to indicate which `ruff` subcommand should be executed by `run_ruff`. At this time, only `check` and `format` are supported. As different subcommands support different parameters, argument generation is delegated based on the specific subcommand value. The `ruff format` subcommand does not currently organize imports and there does not appear to be a way to convince it to do so. Until a unified command exists the approach taken here is to format and then make a second run of `ruff check` that _only_ performs import formatting.
Codes listed in this setting should be included in fixes performed as part of a formatting pass.
23a3770
to
d236f9d
Compare
LGTM, merging. |
Thank you for this change ! |
I plan to wrap up some of the other issues as well as updating the README, but I expect to create a new release today. |
Adds the Subcommand enum to indicate which
ruff
subcommand should be executed byrun_ruff
. At this time, onlycheck
andformat
are supported. As different subcommands support different parameters, argument generation is delegated based on the specific subcommand value.The
ruff format
subcommand does not currently organize imports and there does not appear to be a way to convince it to do so. Until a unified command exists the approach taken here is to format and then make a second run ofruff check
that only performs import formatting.Relates to #53.