Skip to content
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

Closed
lethefrost opened this issue Dec 14, 2023 · 5 comments
Closed

FR: Sort imports on format #363

lethefrost opened this issue Dec 14, 2023 · 5 comments

Comments

@lethefrost
Copy link

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:

    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    },

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 commands ruff.executeOrganizeImports and editor.action.organizeImports that can be bound with shortcuts. However, when I tried to bind them with the same shortcut as Format Document, instead of triggering once and executing both of them, organize imports just replace the action of format 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!

@zanieb
Copy link
Member

zanieb commented Dec 14, 2023

Hi! Thanks for your feedback. This is a duplicate of astral-sh/ruff-lsp#335 so we'll use that to track this instead.

@zanieb zanieb closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2023
@charliermarsh
Copy link
Member

Zanie beat me to it mid-comment but I'll post anyway to say thanks for the kind words :)

@zanieb
Copy link
Member

zanieb commented Dec 14, 2023

See also astral-sh/ruff#8232 and astral-sh/ruff#8367

@lethefrost
Copy link
Author

Hi! Thanks for your feedback. This is a duplicate of astral-sh/ruff-lsp#335 so we'll use that to track this instead.

Thank you for letting me know!

@lethefrost
Copy link
Author

Zanie beat me to it mid-comment but I'll post anyway to say thanks for the kind words :)

and thanks for your kind words too😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants