Skip to content

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

@vitallium

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.

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