on master help sign in
add tree-sitter-embedded-template (erb & ejs) (#2055)

After the incremental parsing rewrite for injections (which was released in 22.03 https://helix-editor.com/news/release-22-03-highlights/#incremental-injection-parsing-rewrite), we can now do combined injections which lets us pull in some templating grammars. The most notable of those is embedded-template - a pretty straightforward grammar that covers ERB and EJS. The grammar and highlights queries are shared between the two but they have different injections.

commit494306ad7ae8ffb45d4d7d906528b64812eee3a5 authorMichael Davis <mcarsondavis@gmail.com> dateSat 9 Apr 2022, 18:23 (5 years ago) parent78b1600
6 files changed+51
book/src/generated/lang-support.md+2 languages.toml+22 runtime/queries/ejs/highlights.scm+12 runtime/queries/ejs/injections.scm+7 runtime/queries/erb/highlights.scm+1 runtime/queries/erb/injections.scm+7
book/src/generated/lang-support.md+2
@@ -9,8 +9,10 @@
99| css | ✓ | | | `vscode-css-language-server` |
1010| dart | ✓ | | ✓ | `dart` |
1111| dockerfile | ✓ | | | `docker-langserver` |
12+| ejs | ✓ | | | |
1213| elixir | ✓ | | | `elixir-ls` |
1314| elm | ✓ | | | `elm-language-server` |
15+| erb | ✓ | | | |
1416| erlang | ✓ | | | `erlang_ls` |
1517| fish | ✓ | ✓ | ✓ | |
1618| git-commit | ✓ | | | |
languages.toml+22
@@ -1088,3 +1088,25 @@ language-server = { command = "sourcekit-lsp" }
10881088[[grammar]]
10891089name = "swift"
10901090source = { git = "https://github.com/Dispersia/tree-sitter-swift", rev = "e75240f89bb3bfd3396155859ae364e5c58d7377" }
1091+
1092+[[language]]
1093+name = "erb"
1094+scope = "text.html.erb"
1095+injection-regex = "erb"
1096+file-types = ["erb"]
1097+roots = []
1098+indent = { tab-width = 2, unit = " " }
1099+grammar = "embedded-template"
1100+
1101+[[language]]
1102+name = "ejs"
1103+scope = "text.html.ejs"
1104+injection-regex = "ejs"
1105+file-types = ["ejs"]
1106+roots = []
1107+indent = { tab-width = 2, unit = " " }
1108+grammar = "embedded-template"
1109+
1110+[[grammar]]
1111+name = "embedded-template"
1112+source = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template", rev = "d21df11b0ecc6fd211dbe11278e92ef67bd17e97" }
runtime/queries/ejs/highlights.scmnew file+12
@@ -0,0 +1,12 @@
1+(comment_directive) @comment
2+
3+[
4+ "<%#"
5+ "<%"
6+ "<%="
7+ "<%_"
8+ "<%-"
9+ "%>"
10+ "-%>"
11+ "_%>"
12+] @keyword
runtime/queries/ejs/injections.scmnew file+7
@@ -0,0 +1,7 @@
1+((content) @injection.content
2+ (#set! injection.language "html")
3+ (#set! injection.combined))
4+
5+((code) @injection.content
6+ (#set! injection.language "javascript")
7+ (#set! injection.combined))
runtime/queries/erb/highlights.scmnew file+1
@@ -0,0 +1 @@
1+; inherits: ejs
runtime/queries/erb/injections.scmnew file+7
@@ -0,0 +1,7 @@
1+((content) @injection.content
2+ (#set! injection.language "html")
3+ (#set! injection.combined))
4+
5+((code) @injection.content
6+ (#set! injection.language "ruby")
7+ (#set! injection.combined))