Skip to content

editor: Fix folding for unindented multiline strings and comments#50049

Merged
smitbarmase merged 2 commits intozed-industries:mainfrom
ryan-m-walker:fix-multiline-string-folding
Mar 19, 2026
Merged

editor: Fix folding for unindented multiline strings and comments#50049
smitbarmase merged 2 commits intozed-industries:mainfrom
ryan-m-walker:fix-multiline-string-folding

Conversation

@ryan-m-walker
Copy link
Copy Markdown
Contributor

Closes #5057

Summary

The indent-based code fold detection does not account for lines inside multiline strings or block comments that have less indentation than the surrounding code. This causes the fold scanner to think the enclosing block ends prematurely.

For example, folding fn main() here would fail because the raw string content at indent level 0 gets treated as the end of the function body:

fn main() {
    let s = r#"
unindented content
"#;
}  

This PR checks whether a low-indent line falls inside a string or comment override region and skips it if so. This works across all languages that define @string or @comment overrides in their overrides.scm.

Before

Screen.Recording.2026-02-24.at.7.45.23.PM.mov

After

Screen.Recording.2026-02-24.at.7.44.27.PM.mov

Test Plan

  • Added test_fold_with_unindented_multiline_raw_string
  • Added test_fold_with_unindented_multiline_block_comment
  • All existing fold tests pass
  • Manually tested both Rust and Python examples

Release Notes:

  • Fixed code folding incorrectly collapsing when multiline strings or block comments contained unindented content

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Feb 25, 2026

We require contributors to sign our Contributor License Agreement, and we don't have @ryan-m-walker on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Feb 25, 2026
@ryan-m-walker
Copy link
Copy Markdown
Contributor Author

ryan-m-walker commented Feb 25, 2026

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 25, 2026
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Feb 25, 2026

The cla-bot has been summoned, and re-checked this pull request!

Copy link
Copy Markdown
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.

Thanks!

@smitbarmase smitbarmase force-pushed the fix-multiline-string-folding branch from 6bea4ad to 09991e1 Compare March 19, 2026 13:37
@smitbarmase smitbarmase merged commit 735eb43 into zed-industries:main Mar 19, 2026
30 checks passed
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
…d-industries#50049)

Closes zed-industries#5057

## Summary

The indent-based code fold detection does not account for lines inside
multiline strings or block comments that have less indentation than the
surrounding code. This causes the fold scanner to think the enclosing
block ends prematurely.

For example, folding `fn main()` here would fail because the raw string
content at indent level 0 gets treated as the end of the function body:

``` rust
fn main() {
    let s = r#"
unindented content
"#;
}  
```

This PR checks whether a low-indent line falls inside a string or
comment override region and skips it if so. This works across all
languages that define `@string` or `@comment` overrides in their
`overrides.scm`.

## Before


https://github.com/user-attachments/assets/a08e6bf8-4f25-4211-8a46-8f6da7e49247

## After


https://github.com/user-attachments/assets/cd5b36db-6d4d-420b-9d60-79f9fad8638e

## Test Plan

- Added `test_fold_with_unindented_multiline_raw_string`
- Added `test_fold_with_unindented_multiline_block_comment`
- All existing fold tests pass
- Manually tested both Rust and Python examples

Release Notes:

- Fixed code folding incorrectly collapsing when multiline strings or
block comments contained unindented content
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
…d-industries#50049)

Closes zed-industries#5057

## Summary

The indent-based code fold detection does not account for lines inside
multiline strings or block comments that have less indentation than the
surrounding code. This causes the fold scanner to think the enclosing
block ends prematurely.

For example, folding `fn main()` here would fail because the raw string
content at indent level 0 gets treated as the end of the function body:

``` rust
fn main() {
    let s = r#"
unindented content
"#;
}  
```

This PR checks whether a low-indent line falls inside a string or
comment override region and skips it if so. This works across all
languages that define `@string` or `@comment` overrides in their
`overrides.scm`.

## Before


https://github.com/user-attachments/assets/a08e6bf8-4f25-4211-8a46-8f6da7e49247

## After


https://github.com/user-attachments/assets/cd5b36db-6d4d-420b-9d60-79f9fad8638e

## Test Plan

- Added `test_fold_with_unindented_multiline_raw_string`
- Added `test_fold_with_unindented_multiline_block_comment`
- All existing fold tests pass
- Manually tested both Rust and Python examples

Release Notes:

- Fixed code folding incorrectly collapsing when multiline strings or
block comments contained unindented content
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…d-industries#50049)

Closes zed-industries#5057

## Summary

The indent-based code fold detection does not account for lines inside
multiline strings or block comments that have less indentation than the
surrounding code. This causes the fold scanner to think the enclosing
block ends prematurely.

For example, folding `fn main()` here would fail because the raw string
content at indent level 0 gets treated as the end of the function body:

``` rust
fn main() {
    let s = r#"
unindented content
"#;
}  
```

This PR checks whether a low-indent line falls inside a string or
comment override region and skips it if so. This works across all
languages that define `@string` or `@comment` overrides in their
`overrides.scm`.

## Before


https://github.com/user-attachments/assets/a08e6bf8-4f25-4211-8a46-8f6da7e49247

## After


https://github.com/user-attachments/assets/cd5b36db-6d4d-420b-9d60-79f9fad8638e

## Test Plan

- Added `test_fold_with_unindented_multiline_raw_string`
- Added `test_fold_with_unindented_multiline_block_comment`
- All existing fold tests pass
- Manually tested both Rust and Python examples

Release Notes:

- Fixed code folding incorrectly collapsing when multiline strings or
block comments contained unindented content
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 first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code fold mistake on multiline string

2 participants