[ty] Preserve delimiters when folding expressions.#24999
Merged
Conversation
1f19b61 to
9dfa6dd
Compare
5c640b9 to
757f62a
Compare
9dfa6dd to
4b69534
Compare
d3ce232 to
0c8981e
Compare
478b0c9 to
fc5374c
Compare
fc5374c to
f481476
Compare
Contributor
Author
|
Back to draft briefly while I handle a few edge cases that I've discovered. |
fdc9314 to
92b6ee9
Compare
38d6634 to
6eef6eb
Compare
MichaReiser
approved these changes
May 18, 2026
| } | ||
|
|
||
| /// Adds a folding range for an expression if it is enclosed in parentheses. | ||
| fn add_parenthesized_expression_range( |
Member
There was a problem hiding this comment.
Do we need to call this for every expression, because expressions can be parenthesized in many places:
if a * (
b
+
c
): ...
Contributor
Author
There was a problem hiding this comment.
Yes, this is unaddressed in the current implementation. I do however I think it slightly different in spirit. My goal here was primarily to improve folds that we already emit, whereas this points at the fact that we don't emit folds for every expression that we might. I think the point is well made, but safe to defer pending further feedback.
6eef6eb to
e0beb6c
Compare
thejchap
pushed a commit
to thejchap/ruff
that referenced
this pull request
May 23, 2026
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? - Does this PR follow our AI policy (https://github.com/astral-sh/.github/blob/main/AI_POLICY.md)? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> This makes it so that we preserve outer delimiters when folding expressions. For instance: ```py x = [ 1, 2, 3, ] ``` now folds like so in a character-precise LSP client: ```py x = [...] ``` rather than like so: ```py x = ... ``` The same behavior applies to parethesized callables, call args, sets, tuples, comprehensions, type parameter lists, and subscripts. **I recommend reviewing this diff commit-by-commit.** Closes astral-sh/ty#3427. ## Test Plan Please see updated tests. <!-- How was it tested? -->
anishgirianish
pushed a commit
to anishgirianish/ruff
that referenced
this pull request
May 28, 2026
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? - Does this PR follow our AI policy (https://github.com/astral-sh/.github/blob/main/AI_POLICY.md)? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> This makes it so that we preserve outer delimiters when folding expressions. For instance: ```py x = [ 1, 2, 3, ] ``` now folds like so in a character-precise LSP client: ```py x = [...] ``` rather than like so: ```py x = ... ``` The same behavior applies to parethesized callables, call args, sets, tuples, comprehensions, type parameter lists, and subscripts. **I recommend reviewing this diff commit-by-commit.** Closes astral-sh/ty#3427. ## Test Plan Please see updated tests. <!-- How was it tested? -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This makes it so that we preserve outer delimiters when folding expressions. For instance:
now folds like so in a character-precise LSP client:
rather than like so:
The same behavior applies to parethesized callables, call args, sets, tuples, comprehensions, type parameter lists, and subscripts.
I recommend reviewing this diff commit-by-commit.
Closes astral-sh/ty#3427.
Test Plan
Please see updated tests.