Skip to content

Conversation

@janko
Copy link
Contributor

@janko janko commented Oct 10, 2025

I believe this is what's needed to enable the editor::WrapSelectionsInTag action in HTML+ERB files. It worked on initial release, but I think at some point the implementation was generalized by letting languages specify wrap_characters, so currently it only works in pure HTML files.

@cla-bot cla-bot bot added the cla-signed label Oct 10, 2025
@vitallium vitallium self-assigned this Oct 10, 2025
@vitallium
Copy link
Collaborator

@janko looks great! Can you please check the pipeline before we merge this? Thanks!

@janko janko force-pushed the wrap-selections-in-tag branch from c888312 to 383b316 Compare October 10, 2025 14:44
@janko
Copy link
Contributor Author

janko commented Oct 10, 2025

@vitallium Fixed ✅

@vitallium
Copy link
Collaborator

@vitallium Fixed ✅

Awesome, thank you!

@vitallium vitallium merged commit 68e0cab into zed-extensions:main Oct 10, 2025
4 checks passed
@vitallium
Copy link
Collaborator

vitallium commented Oct 10, 2025

Aaand I failed to land the proper commit because of GitHub:

68e0cab (HEAD -> main, origin/main, origin/HEAD) Enable `editor::WrapSelectionsInTag` action in HTML+ERB files (#191)
3ed9aea chore: update CHANGELOG.md

@janko
Copy link
Contributor Author

janko commented Oct 15, 2025

@vitallium It seems this didn't fix the issue – the editor::WrapSelectionsInTag action is still unavailable in my .html.erb files. Any ideas how to resolve this?

EDIT: Claude Code is suggesting adding wrap_characters to languages/erb/config.toml, but I'm not sure how that would help.

LLM output
⏺ Based on my extensive investigation, I now understand the issue. The "HTML+ERB" language is likely created dynamically when HTML has ERB injections. Let me verify this by
  checking your actual ERB language config to see if it sets wrap_characters:

  The issue is that you need to add wrap_characters to BOTH the HTML language config AND your ERB language config because:

  1. When you're in HTML regions of the .erb file, language_at() returns HTML
  2. When you're inside <% %> tags, language_at() returns ERB
  3. The "HTML+ERB" is just a display name—the actual language detection depends on cursor position

  Since your ERB config at /Users/janko/Code/clones/zed-ruby/languages/erb/config.toml doesn't have wrap_characters, the action won't be available when your cursor is inside
   ERB tags.

  Solution: Add wrap_characters to your ERB config:

⏺ Update(~/Code/clones/zed-ruby/languages/erb/config.toml)
  ⎿  User rejected update to ../zed-ruby/languages/erb/config.toml
        6        { start = "<", end = ">", close = true, newline = true },
        7    ]
        8    block_comment = ["<%#", "%>"]
        9 +  wrap_characters = { start_prefix = "<", start_suffix = ">", end_prefix = "</", end_suffix = ">" }
       10    scope_opt_in_language_servers = ["tailwindcss-language-server"]

@vitallium
Copy link
Collaborator

vitallium commented Oct 17, 2025

@vitallium It seems this didn't fix the issue – the editor::WrapSelectionsInTag action is still unavailable in my .html.erb files. Any ideas how to resolve this?

EDIT: Claude Code is suggesting adding wrap_characters to languages/erb/config.toml, but I'm not sure how that would help.

LLM output

Hi! Do you have an example? Handling of ERB templates is quite tricky because of how Zed parses them. Consider the following example:

<div>Hi!</div>
<%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>

The 1st line uses ERB grammar, so it uses everything applicable to HTML+ERB.
The 2nd line is Ruby (technically, only what’s inside <%= and %>), so it uses everything applicable to the Ruby language.

@janko
Copy link
Contributor Author

janko commented Oct 17, 2025

If I take your example, and put it in an .html.erb file, I would like that when I create a new line below <div> and press cmd-shift-p, that editor: wrap selections in tag action is available in the list.

This is the behavior that I get if I change the language from HTML+ERB to HTML in the language picker. Any idea what's needed to achieve that?

@vitallium
Copy link
Collaborator

vitallium commented Oct 17, 2025

If I take your example, and put it in an .html.erb file, I would like that when I create a new line below <div> and press cmd-shift-p, that editor: wrap selections in tag action is available in the list.

This is the behavior that I get if I change the language from HTML+ERB to HTML in the language picker. Any idea what's needed to achieve that?

Ah, I remember now. Good news: this is an issue with Zed itself. The editor: wrap selections in tag action works as follows:

  1. Grab the selection, if any
  2. Get the underlying language for that selection
  3. Check if the language has a wrap_characters configuration option
  4. If such a config option exists, this action becomes available.

That works for 90% of languages, but ERB is special. ERB is not a language technically; it’s a configuration of ERB that produces a syntax tree consisting of two languages via injections: HTML and Ruby. The final syntax tree can be treated as one that includes both languages. Zed parses the file using the provided tree-sitter grammar, which includes HTML and Ruby injections. Zed uses these to load the corresponding grammars for each language. This results in three languages being used in an editor that displays an ERB template:

  1. Base: HTML+ERB
  2. HTML for every content node
  3. Ruby for every code node

When Zed asks for the underlying language at a given point, it simply uses the last available language, which is Ruby. Since this language does not have wrap_characters configured, the action is not available.

Bad news: the last time I checked the corresponding issue upstream, there was no progress because this functionality is a core feature and changing it could be risky. Also, since we don’t have many languages with such unusual grammar parsing, this issue has low priority.

Sorry that such a simple and useful feature doesn’t work in Zed due to this issue. I hope it will be fixed someday. Thanks!

@janko
Copy link
Contributor Author

janko commented Oct 20, 2025

Appreciate the detailed explanation 🙏🏻 I opened zed-industries/zed#40632, so we'll see if that helps.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants