language: Improve auto-indentation when using round brackets in Python (#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.
This commit is contained in:
Finn Evers 2025-05-24 22:55:15 +02:00 committed by GitHub
parent a204510cfc
commit 4c28d2c2e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 4 deletions

View file

@ -1236,12 +1236,12 @@ mod tests {
"def a():\n \n if a:\n b()\n else:\n "
);
// indent after an open paren. the closing paren is not indented
// indent after an open paren. the closing paren is not indented
// because there is another token before it on the same line.
append(&mut buffer, "foo(\n1)", cx);
assert_eq!(
buffer.text(),
"def a():\n \n if a:\n b()\n else:\n foo(\n 1)"
"def a():\n \n if a:\n b()\n else:\n foo(\n 1)"
);
// dedent the closing paren if it is shifted to the beginning of the line

View file

@ -1,3 +1,4 @@
(_ "(" ")" @end) @indent
(_ "[" "]" @end) @indent
(_ "{" "}" @end) @indent