-
Notifications
You must be signed in to change notification settings - Fork 56
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
FR: Sort imports on format #363
Comments
Hi! Thanks for your feedback. This is a duplicate of astral-sh/ruff-lsp#335 so we'll use that to track this instead. |
Zanie beat me to it mid-comment but I'll post anyway to say thanks for the kind words :) |
See also astral-sh/ruff#8232 and astral-sh/ruff#8367 |
Thank you for letting me know! |
and thanks for your kind words too😊 |
Hi there, if I didn't miss something, for the current version of Ruff extension there's a way to auto sort the imports on save, by adding the following settings:
However, I didn't find any information about how to sort on format. I hope to sort the imports when I trigger
Format Document
command (mostly by shortcut). I noticed there are commandsruff.executeOrganizeImports
andeditor.action.organizeImports
that can be bound with shortcuts. However, when I tried to bind them with the same shortcut asFormat Document
, instead of triggering once and executing both of them,organize imports
just replace the action offormat document
.Can only auto sort on save can sometimes cause inconvenience. For example, in daily use with writing your own code, for convenience, you might want to keep this setting on. However, sometimes you would have to work on someone else's code who doesn't follow style guides at all. In this case, when you only want to modify a small part of the file, and don't want to or have to do the heavy job to refactor and clean the whole file, it will be very awkward when you save the file and find the extension just sorting the imports which have to be ordered in a specific way for the program to run properly. Then you have to turn the sort-on-save setting on and off all the time. That's why I think it would be nice to have a feature to sort-on-format, 'cause you are not likely to execute the formatter on the others' files which are not intended to follow specific style guides, but you will always need to save files after editing.
Thank you for your efforts on this great extension!
The text was updated successfully, but these errors were encountered: