Fix line comment rewrap in golang and C/C++ - #54931
Merged
NeelChotai merged 2 commits intoApr 27, 2026
Merged
Conversation
…k-comment prefix Adds two tests covering the regression in zed-industries#54737 - `test_rewrap_line_comment_in_go` uses the `go` config, which has the empty-prefix `block_comment` that triggered the regression. This adds tree-sitter-go as a new package dependency. - `test_rewrap_line_comment_in_c` uses the `c` config and tree-sitter-c grammar. This also covers C++ since they share both the comment-format detection path and an empty-prefix `block_comment`. Both tests fail prior to the accompanying fix and pass after.
Fixes zed-industries#54737. PR zed-industries#48752 added empty-prefix `block_comment` entries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action. In `Editor::rewrap_impl`, the comment-format matcher used `buffer.contains_str_at(indent_end, &config.prefix)` to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line. `//` (and `#`) line comments inside a `comment` override scope were classified as `BlockLine("")` and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding `//` markers as text in the wrapped paragraph. Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to `line_comment_prefixes`.
NeelChotai
approved these changes
Apr 27, 2026
NeelChotai
enabled auto-merge
April 27, 2026 08:48
Member
|
Awesome! Thanks for the contribution. |
|
Thanks for the fix! This was a pretty annoying regression. |
ebaah46
pushed a commit
to ebaah46/zed
that referenced
this pull request
May 6, 2026
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#54737. zed-industries#48752 added empty-prefix `block_comment` entries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action. In `Editor::rewrap_impl`, the comment-format matcher used `buffer.contains_str_at(indent_end, &config.prefix)` to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line. `//` (and `#`) line comments inside a `comment` override scope were classified as `BlockLine("")` and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding `//` markers as text in the wrapped paragraph. Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to `line_comment_prefixes`. I've included regression tests for both golang (which adds a new treesitter dep to the editor package) and C/C++. Release Notes: - Fixed line comment rewrapping in golang and C/C++
kathbigra
pushed a commit
to kathbigra/zed
that referenced
this pull request
May 10, 2026
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#54737. zed-industries#48752 added empty-prefix `block_comment` entries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action. In `Editor::rewrap_impl`, the comment-format matcher used `buffer.contains_str_at(indent_end, &config.prefix)` to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line. `//` (and `#`) line comments inside a `comment` override scope were classified as `BlockLine("")` and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding `//` markers as text in the wrapped paragraph. Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to `line_comment_prefixes`. I've included regression tests for both golang (which adds a new treesitter dep to the editor package) and C/C++. Release Notes: - Fixed line comment rewrapping in golang and C/C++
jonx
pushed a commit
to jonx/zed-aros
that referenced
this pull request
Jul 17, 2026
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#54737. zed-industries#48752 added empty-prefix `block_comment` entries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action. In `Editor::rewrap_impl`, the comment-format matcher used `buffer.contains_str_at(indent_end, &config.prefix)` to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line. `//` (and `#`) line comments inside a `comment` override scope were classified as `BlockLine("")` and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding `//` markers as text in the wrapped paragraph. Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to `line_comment_prefixes`. I've included regression tests for both golang (which adds a new treesitter dep to the editor package) and C/C++. Release Notes: - Fixed line comment rewrapping in golang and C/C++
jolutz
pushed a commit
to jolutz/zed
that referenced
this pull request
Aug 8, 2026
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Closes zed-industries#54737. zed-industries#48752 added empty-prefix `block_comment` entries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action. In `Editor::rewrap_impl`, the comment-format matcher used `buffer.contains_str_at(indent_end, &config.prefix)` to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line. `//` (and `#`) line comments inside a `comment` override scope were classified as `BlockLine("")` and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding `//` markers as text in the wrapped paragraph. Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to `line_comment_prefixes`. I've included regression tests for both golang (which adds a new treesitter dep to the editor package) and C/C++. Release Notes: - Fixed line comment rewrapping in golang and C/C++
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
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.
Self-Review Checklist:
Closes #54737.
#48752 added empty-prefix
block_commententries to several language configs (Go, C, C++, JSONC, Python, JSX inner) to support the new toggle-block-comments action.In
Editor::rewrap_impl, the comment-format matcher usedbuffer.contains_str_at(indent_end, &config.prefix)to decide whether the current line is a continuation of a block comment. When the language is configured with an empty prefix, this is true on every line.//(and#) line comments inside acommentoverride scope were classified asBlockLine("")and never reached the line-comment fallback. The result was that the line-comment prefix was not stripped before wrapping and not re-prepended after, embedding//markers as text in the wrapped paragraph.Skip the BlockLine arm when the configured prefix is empty so the matcher falls through to
line_comment_prefixes.I've included regression tests for both golang (which adds a new treesitter dep to the editor package) and C/C++.
Release Notes: