Skip to content

language: Improve auto-indentation when using round brackets in Python #31260

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

Merged
merged 1 commit into from
May 24, 2025

Conversation

MrSubidubi
Copy link
Contributor

@MrSubidubi MrSubidubi commented May 23, 2025

Follow-up to #29625 and #30902

This PR reintroduces auto-intents for brackets in Python and fixes some cases where an indentation would be triggered if it should not. For example, upon typing

a = []

and inserting a newline after, the next line would be indented although it shoud not be.

Bracket auto-indentation was tested prior to #29625 but removed there and the test updated accordingly. #30902 reintroduced this for all brackets but (). I reintroduced this here, reverted the changes to the test so that indents also happen after typing (). This is frequently used for tuples and multiline statements in Python.

Release Notes:

  • Improved auto-indentation when using round brackets in Python.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label May 23, 2025
@MrSubidubi

This comment has been minimized.

Copy link
Member

@smitbarmase smitbarmase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see it back, thank you so much!

@smitbarmase smitbarmase changed the title python: Improve indentation with brackets present language: Improve auto-indentation when using round brackets in Python May 24, 2025
@smitbarmase smitbarmase merged commit 4c28d2c into zed-industries:main May 24, 2025
25 checks passed
@MrSubidubi MrSubidubi deleted the python-indent-followup branch May 25, 2025 07:43
smitbarmase pushed a commit that referenced this pull request May 27, 2025
#31260)

Follow-up to #29625 and #30902

This PR reintroduces auto-intents for brackets in Python and fixes some
cases where an indentation would be triggered if it should not. For
example, upon typing

```python
a = []
```
and inserting a newline after, the next line would be indented although
it shoud not be.

Bracket auto-indentation was tested prior to #29625 but removed there
and the test updated accordingly. #30902 reintroduced this for all
brackets but `()`. I reintroduced this here, reverted the changes to the
test so that indents also happen after typing `()`. This is frequently
used for tuples and multiline statements in Python.

Release Notes:

- Improved auto-indentation when using round brackets in Python.
smitbarmase added a commit that referenced this pull request May 27, 2025
We [recently](#31260) added a
condition which fixes certain edge cases detecting indent ranges when a
bracket pair is on the same row for suggested indent languages. This PR
adds a test for that so we don't regress in the future. Ref:
#31362


https://github.com/zed-industries/zed/blob/f9592c6b9273738808210c3a2ab7a366258c7f71/crates/language/src/buffer.rs#L2910

Release Notes:

- N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants