-
Notifications
You must be signed in to change notification settings - Fork 4.7k
language: Fix indent suggestions for significant indented languages like Python #29625
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
Conversation
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
f1feee2
to
38effc6
Compare
ac1622d
to
1dcbbf4
Compare
lj3954
pushed a commit
to lj3954/zed
that referenced
this pull request
May 9, 2025
…ike Python (zed-industries#29625) Closes zed-industries#26157 This fixes multiple cases where Python indentation breaks: - [x] Adding a new line after `if`, `try`, etc. correctly indents in that scope - [x] Multi-cursor tabs correctly preserve relative indents - [x] Adding a new line after `else`, `finally`, etc. correctly outdents them - [x] Existing Tests Future Todo: I need to add new tests for all the above cases. Before/After: 1. Multi-cursor tabs correctly preserve relative indents https://github.com/user-attachments/assets/08a46ddf-5371-4e26-ae7d-f8aa0b31c4a2 2. Adding a new line after `if`, `try`, etc. correctly indents in that scope https://github.com/user-attachments/assets/9affae97-1a50-43c9-9e9f-c1ea3a747813 Release Notes: - Fixes indentation-related issues involving tab, newline, etc for Python.
This was referenced May 11, 2025
smitbarmase
added a commit
that referenced
this pull request
May 18, 2025
This PR add tests for a recent PR: [language: Fix indent suggestions for significant indented languages like Python](#29625) It also covers cases from past related issues so that we don't end up circling back to them on future fixes. - [Python incorrect auto-indentation for except:](#10832) - [Python for/while...else indention overridden by if statement ](#30795) - [Python: erroneous indent on newline when comment ends in :](#25416) - [Newline in Python file does not indent ](#16288) - [Tab Indentation works incorrectly when there are multiple cursors](#26157) Release Notes: - N/A
smitbarmase
pushed a commit
that referenced
this pull request
May 24, 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
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
Jun 26, 2025
Closes #33238, follow-up to #29625. Changes: - Removed `significant_indentation`, which was the way to introduce indentation scoping in languages like Python. However, it turned out to be unnecessarily complicated to define and maintain. - Introduced `decrease_indent_patterns`, which takes a `pattern` keyword to automatically outdent and `valid_after` keywords to treat as valid code points to snap to. The outdent happens to the most recent `valid_after` keyword that also has less or equal indentation than the currently typed keyword. Fixes: 1. In Python, typing `except`, `finally`, `else`, and so on now automatically indents intelligently based on the context in which it appears. For instance: ```py try: if a == 1: try: b = 2 ^ # <-- typing "except:" here would indent it to inner try block ``` but, ```py try: if a == 1: try: b = 2 ^ # <-- typing "except:" here would indent it to outer try block ``` 2. Fixes comments not maintaining indent. Release Notes: - Improved auto outdent for Python while typing keywords like `except`, `else`, `finally`, etc. - Fixed the issue where comments in Python would not maintain their indentation.
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jun 28, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 1, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 4, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
aviatesk
added a commit
to aviatesk/zed-julia
that referenced
this pull request
Jul 4, 2025
This commit adds both regex-based and Tree-sitter-based indentation rules to provide a smooth editing experience for Julia coding in Zed. Motivation - this didn't work properly before: ```julia if x elseif y else # <- wouldn't auto-outdent end ``` Changes: - Add `increase_indent_pattern` for Julia block keywords - Add `decrease_indent_patterns` with context-aware `valid_after` rules - Add `@start.suffix` captures in indents.scm for tracking block beginnings (required for `decrease_indent_patterns` to be functional) - Update `@outdent` patterns to work with specific keywords The dual approach (regex + Tree-sitter) is intentional, following Zed's design pattern established for Python (see zed-industries/zed#29625, zed-industries/zed#33370).
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.
Closes #26157
This fixes multiple cases where Python indentation breaks:
if
,try
, etc. correctly indents in that scopeelse
,finally
, etc. correctly outdents themFuture Todo: I need to add new tests for all the above cases.
Before/After:
python-1.mp4
if
,try
, etc. correctly indents in that scopepython-2.mp4
Release Notes: