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

Range formatting #7233

Closed
MichaReiser opened this issue Sep 8, 2023 · 9 comments · Fixed by #9733
Closed

Range formatting #7233

MichaReiser opened this issue Sep 8, 2023 · 9 comments · Fixed by #9733
Assignees
Labels
formatter Related to the formatter

Comments

@MichaReiser
Copy link
Member

For IDE integration, it would be great if it was possible to select a certain range of code and only format that range.

@MichaReiser MichaReiser added the formatter Related to the formatter label Sep 8, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Sep 8, 2023
@T-256
Copy link
Contributor

T-256 commented Sep 8, 2023

Thats cool, not just one range, but batch range formatting.

@MichaReiser
Copy link
Member Author

Thats cool, not just one range, but batch range formatting.

Oh, I didn't know about that. We'll start with one range but being aware of multi range formatting may help us to decide on the design

@MichaReiser
Copy link
Member Author

@konstin
Copy link
Member

konstin commented Sep 8, 2023

do you know what's the use case for this from the editor side?

@MichaReiser
Copy link
Member Author

I assume it's to speed up "Format changed code" when saving a file with multiple non-overlapping changed ranges.

@KraXen72
Copy link

KraXen72 commented Oct 3, 2023

do you know what's the use case for this from the editor side?

For example, VSCode's format selection command. i use it most of the time instead of formatting the entire document.

@konstin
Copy link
Member

konstin commented Oct 20, 2023

Current state (only very basic statement range formatting): https://github.com/astral-sh/ruff/tree/range-formatting

@skykasko
Copy link
Contributor

skykasko commented Nov 8, 2023

FYI, this capability has recently been added to Black (psf/black#4020).

@LazyRen
Copy link

LazyRen commented Dec 21, 2023

do you know what's the use case for this from the editor side?

Addition to the format selection command, it seems Format on Save Mode: modifications also depend on this feature.

Currently, Ruff doesn't format the document automatically even if format on save is enabled if Format on Save Mode is set to modifications.

@MichaReiser MichaReiser self-assigned this Jan 24, 2024
@MichaReiser MichaReiser linked a pull request Jan 27, 2024 that will close this issue
@MichaReiser MichaReiser removed a link to a pull request Jan 29, 2024
This was referenced Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants