# Fix line comment rewrap in golang and C/C\+\+ \(\#54931\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/f506d161286b0f6fbe1e9704cca0534c303077da)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: f506d161286b0f6fbe1e9704cca0534c303077da

Requested commit: f506d161286b0f6fbe1e9704cca0534c303077da

Commit: f506d161286b0f6fbe1e9704cca0534c303077da

Tree: dacde73124d196140950da1619dc413d12ab7fba

Author: Nathan Witmer

Committer: GitHub

## Message

```
Fix line comment rewrap in golang and C/C++ (#54931)

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

## Parents

- [b767996b8bf7e45968726399b4450e9adc783a75](https://git.cafe/gitcafe/zed/commit/b767996b8bf7e45968726399b4450e9adc783a75?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/f506d161286b0f6fbe1e9704cca0534c303077da?format=markdown)
