Skip to content

Fix line comment rewrap in golang and C/C++ - #54931

Merged
NeelChotai merged 2 commits into
zed-industries:mainfrom
zerowidth:fix-line-comment-rewrap
Apr 27, 2026
Merged

Fix line comment rewrap in golang and C/C++#54931
NeelChotai merged 2 commits into
zed-industries:mainfrom
zerowidth:fix-line-comment-rewrap

Conversation

@zerowidth

@zerowidth zerowidth commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Closes #54737.

#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++

…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`.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 26, 2026
@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 Apr 26, 2026
@zerowidth zerowidth changed the title Fix line comment rewrap Fix line comment rewrap in golang and C/C++ Apr 26, 2026
@NeelChotai
NeelChotai enabled auto-merge April 27, 2026 08:48
@NeelChotai

Copy link
Copy Markdown
Member

Awesome! Thanks for the contribution.

@NeelChotai
NeelChotai added this pull request to the merge queue Apr 27, 2026
Merged via the queue into zed-industries:main with commit f506d16 Apr 27, 2026
43 checks passed
@cee-dub

cee-dub commented Apr 28, 2026

Copy link
Copy Markdown

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++
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.

Rewrap support in Go comments broken in recent update

4 participants