Skip to content

html-erb: Implement context-aware comment toggling #264

Description

@vitallium

Problem

Comment toggling in .html.erb files is naive. The current config sets:

block_comment = ["<%#", "%>"]

This always wraps selections with ERB comment syntax regardless of context. In practice, .html.erb files mix two distinct comment styles:

  • ERB tags → <%# code %> (insert # after <%)
  • HTML content → <!-- content -->

Toggling a comment on an HTML line like <div class="foo"> produces <%#<div class="foo">%> — invalid ERB. The correct output would be <!-- <div class="foo"> -->.

There is also no line comment support, so ⌘/ does nothing useful. yaml-erb has no comment support whatsoever.

Prior Art

Herb's language server shipped exactly this logic in marcoroth/herb#1308. The CommentService classifies each line as erb-tag, erb-comment, html-comment, or html-content by walking the AST, applies the appropriate comment style per line, and handles mixed selections intelligently.

Discussed as a candidate for the Zed Ruby Extension.

Activity

  1. added theissue type on Mar 10, 2026
  2. changed the issue type fromtoon Mar 10, 2026
  3. marcoroth commented on Mar 10, 2026

    @marcoroth
    Contributor

    I think this is mostly blocked by this issue in Zed: zed-industries/zed#20042

    I have been prototyping to add arbitrary LSP requests to Zed itself, and it does seem to work. I wonder if it's worth a PR to zed-industries/zed 🤔

  4. vitallium commented on Mar 10, 2026

    @vitallium
    CollaboratorAuthor

    I think this is mostly blocked by this issue in Zed: zed-industries/zed#20042

    I have been prototyping to add arbitrary LSP requests to Zed itself, and it does seem to work. I wonder if it's worth a PR to zed-industries/zed 🤔

    Yeah, I have been playint with a similar concept. I think the idea makes sense in general, but on the LSP level: special requests/responses for delegating comment handling to language servers, e.g. experimental/toggleComment (or something similar). Right now, herb uses the herb prefix, so adding a special LSP command just for it would probably be rejected by the Zed team, but asking to land something more general, I think, has more chances.

  5. marcoroth commented on Mar 10, 2026

    @marcoroth
    Contributor

    Yeah that makes sense! My prototype just has a general send_language_server_request on the Zed/Editor level, that the Zed Ruby Extension then can use to send the specific toggleComment request to the language server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions