Skip to content

editor: Trim indent guides at last non-empty line #29482

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 2 commits into from
May 12, 2025

Conversation

ronharel02
Copy link
Contributor

@ronharel02 ronharel02 commented Apr 26, 2025

Closes #26274

Adjust the end position of indent guides to prevent them from extending through empty space.
Also corrected old test values ​​that seemed to have adapted to the indentation's behavior.

Release Notes:

  • Fixed indentation guides extending beyond the final scope in a file.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Apr 26, 2025
@ronharel02 ronharel02 force-pushed the rharel/trim-indent-guides branch from 2f7dd5f to 61da916 Compare April 26, 2025 15:52
Previously, when no non-empty lines where found when scanning ahead of an empty one, the empty line would inherit its parent block's depth.
Changed this to fallback to 0, ensuring guides stop at the last non-empty line.
@ronharel02
Copy link
Contributor Author

ronharel02 commented Apr 27, 2025

After looking further into MultiBufferSnapshot::indent_guides_in_range's implementation, which initially looked valid, I realised the solution could be much simpler.
Upon reaching an empty line, if no indent can be found ahead the current depth is used as a fallback for the depth of the line - resulting in no action; But in practice we want to terminate all guides in the last non-empty line, which happens when depth < current_depth and applies to indents up to the diff, meaning 0 should be used.

@ronharel02 ronharel02 force-pushed the rharel/trim-indent-guides branch from 61da916 to e1dedea Compare April 27, 2025 20:29
@bennetbo bennetbo self-assigned this Apr 28, 2025
Copy link
Contributor

@AaronFeickert AaronFeickert left a comment

Choose a reason for hiding this comment

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

Not sure if external reviews are welcome here, but LGTM.

@bennetbo
Copy link
Contributor

Thanks!

@bennetbo bennetbo merged commit 6592314 into zed-industries:main May 12, 2025
19 checks passed
dive pushed a commit to dive/zed that referenced this pull request May 12, 2025
Closes zed-industries#26274

Adjust the end position of indent guides to prevent them from extending
through empty space.
Also corrected old test values ​​that seemed to have adapted to the
indentation's behavior.

Release Notes:

- Fixed indentation guides extending beyond the final scope in a file.
osiewicz pushed a commit that referenced this pull request May 15, 2025
Closes #26274

Adjust the end position of indent guides to prevent them from extending
through empty space.
Also corrected old test values ​​that seemed to have adapted to the
indentation's behavior.

Release Notes:

- Fixed indentation guides extending beyond the final scope in a file.
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.

Indentation guides extend 1 line too long at end of file
3 participants