Skip to content

ERB injection for other source languages - #113

Merged
vitallium merged 1 commit into
zed-extensions:mainfrom
joeldrapper:erb-for-other-source-languages
Jun 27, 2025
Merged

ERB injection for other source languages#113
vitallium merged 1 commit into
zed-extensions:mainfrom
joeldrapper:erb-for-other-source-languages

Conversation

@joeldrapper

@joeldrapper joeldrapper commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

ERB can be used to template any kind of source file — not just HTML. However, it’s most commonly used for generating HTML, YAML and Ruby source.

This PR updates the ERB language to be more generic, treating .erb files as plain text with Ruby injections within the ERB template tags.

It then introduces two new languages: HTML/ERB and YAML/ERB, which handle switching between HTML and Ruby and YAML and Ruby respectively.

I attempted to make a specialised language for Ruby/ERB, but couldn’t get past some basic syntax highlighting issues. I think it’s quite reasonable to highlight .rb.erb files as plain text with Ruby inside the ERB tags since it would be very difficult to guess at how the generated Ruby will look structurally. It’s certainly an improvement on treating it like HTML.

I’ve configured mappings from ERB, HTML/ERB and YAML/ERB for Ruby LSP, which will handle them all as erb. I’ve also updated the Herb LSP to handle HTML/ERB files specifically.

Next steps

I would be nice if the YAML language server was configured to run on YAML/ERB files. I believe this can be done by updating this file.

However, I don’t think this is a blocker as most YAML/ERB files are actually named .yml not .yml.erb and so will be treated as regular old YAML files.

@cla-bot cla-bot Bot added the cla-signed label Jun 23, 2025
@kaspth

kaspth commented Jun 23, 2025

Copy link
Copy Markdown

I wonder if @marcoroth has thoughts on this given his HERB work.

@joeldrapper

Copy link
Copy Markdown
Contributor Author

I wonder if unmatched .erb files should just be plain text outside of the ERB tags. I would much rather my .rb.erb file was like that than treated as an HTML/ERB file.

@joeldrapper

Copy link
Copy Markdown
Contributor Author

Here’s what that looks like.

Screenshot 2025-06-23 at 17 29 44

I think this is a good solution for Ruby and other files, but I still haven't figured out how to enable the YAML language server.

@joeldrapper

Copy link
Copy Markdown
Contributor Author

I think because YAML is a built-in language server, it will actually need to be associated in this file. https://github.com/zed-industries/zed/blob/a067c16c823354da63966273ac15d1aa93c0e922/crates/languages/src/lib.rs#L98

@joeldrapper
joeldrapper force-pushed the erb-for-other-source-languages branch from bd59c30 to 2848538 Compare June 23, 2025 17:07
@joeldrapper

joeldrapper commented Jun 23, 2025

Copy link
Copy Markdown
Contributor Author

There’s one more problem that’s come up. The language ID is being passed through to Ruby LSP as HTML/ERB or YAML/ERB and RubyLSP doesn’t support those languages. It only supports Ruby or ERB.

We will need a way to map YAML/ERB and HTML/ERB to ERB because as that’s all the language server cares about.

I think this will require upstream changes in the zed_extension_api crate.

Here is an example of the RPS message with the wrong languageId.

{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///Users/joeldrapper/src/zed-ruby/example.html.erb","languageId":"html/erb","version":0,"text":""}}}

@joeldrapper

Copy link
Copy Markdown
Contributor Author

Looks like this was already supported, I just need to add the mappings.

So the final issue is that the YAML language server isn’t being enabled, but that has to be fixed in the main Zed repo.

@joeldrapper
joeldrapper force-pushed the erb-for-other-source-languages branch from cbf7fe6 to 1f93916 Compare June 23, 2025 18:04
@joeldrapper
joeldrapper marked this pull request as ready for review June 23, 2025 18:05
@joeldrapper
joeldrapper force-pushed the erb-for-other-source-languages branch from 1f93916 to 9b7fc09 Compare June 23, 2025 18:06
@vitallium

Copy link
Copy Markdown
Collaborator

@joeldrapper Thanks! This awesome improvement works like a charm!

@vitallium
vitallium merged commit 14a913e into zed-extensions:main Jun 27, 2025
@cole-miller cole-miller mentioned this pull request Jun 27, 2025
cole-miller added a commit that referenced this pull request Jun 27, 2025
There was a bug in zed_extension_cli that prevented debug adapters in
extensions from being successfully registered. zed_extension_cli has
been fixed (zed-industries/extensions#2927), but
we need to bump the version of this and the Swift extension so they'll
get rebuild and republished using the fixed CLI.

This version includes:

- #119
- #111
- #113
cole-miller added a commit to zed-industries/extensions that referenced this pull request Jun 27, 2025
This version includes:

- zed-extensions/ruby#119
- zed-extensions/ruby#111
- zed-extensions/ruby#113

Also, as a result of rebuilding the extension with #2927, the new rdbg
debug adapter will be registered successfully.
SomeoneToIgnore pushed a commit to zed-industries/zed that referenced this pull request Jul 4, 2025
Closes [#133](zed-extensions/ruby#133)

This PR enables the Emmet LS in `HTML/ERB` files that we added in the
zed-extensions/ruby#113. Let me know if I picked
the right approach here.

Thanks!

Release Notes:

- N/A
notpeter pushed a commit to zed-industries/zed that referenced this pull request Jul 19, 2025
Closes #27118
Closes #34165

Fix a small issue after we landed
zed-extensions/ruby#113 where we introduced
`HTML/ERB` and `YAML/ERB` language IDs to improve user experience. Sorry
about that. Thanks!

Release Notes:

- N/A
notpeter pushed a commit to zed-industries/zed that referenced this pull request Jul 19, 2025
Closes #27118
Closes #34165

Fix a small issue after we landed
zed-extensions/ruby#113 where we introduced
`HTML/ERB` and `YAML/ERB` language IDs to improve user experience. Sorry
about that. Thanks!

Release Notes:

- N/A
maxdeviant pushed a commit to zed-extensions/emmet that referenced this pull request Aug 16, 2025
Closes [#133](zed-extensions/ruby#133)

This PR enables the Emmet LS in `HTML/ERB` files that we added in the
zed-extensions/ruby#113. Let me know if I picked
the right approach here.

Thanks!

Release Notes:

- N/A
orual pushed a commit to orual/zed that referenced this pull request Aug 23, 2025
Closes zed-industries#27118
Closes zed-industries#34165

Fix a small issue after we landed
zed-extensions/ruby#113 where we introduced
`HTML/ERB` and `YAML/ERB` language IDs to improve user experience. Sorry
about that. Thanks!

Release Notes:

- N/A
kumamaki pushed a commit to kumamaki/zed-extensions that referenced this pull request May 5, 2026
This version includes:

- zed-extensions/ruby#119
- zed-extensions/ruby#111
- zed-extensions/ruby#113

Also, as a result of rebuilding the extension with zed-industries#2927, the new rdbg
debug adapter will be registered successfully.
jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
Closes [#133](zed-extensions/ruby#133)

This PR enables the Emmet LS in `HTML/ERB` files that we added in the
zed-extensions/ruby#113. Let me know if I picked
the right approach here.

Thanks!

Release Notes:

- N/A
jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
Closes #27118
Closes #34165

Fix a small issue after we landed
zed-extensions/ruby#113 where we introduced
`HTML/ERB` and `YAML/ERB` language IDs to improve user experience. Sorry
about that. Thanks!

Release Notes:

- N/A
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.

3 participants