summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Davis2022-04-09 23:23:06 +0000
committerGitHub2022-04-09 23:23:06 +0000
commit494306ad7ae8ffb45d4d7d906528b64812eee3a5 (patch)
treecf2315f7e36c1e57012be39038959800c283db95
parent78b16009433041059597cc6ccea28c17254483b7 (diff)
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.
-rw-r--r--book/src/generated/lang-support.md2
-rw-r--r--languages.toml22
-rw-r--r--runtime/queries/ejs/highlights.scm12
-rw-r--r--runtime/queries/ejs/injections.scm7
-rw-r--r--runtime/queries/erb/highlights.scm1
-rw-r--r--runtime/queries/erb/injections.scm7
6 files changed, 51 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 4e8e1c82..efafc3e5 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -9,8 +9,10 @@
| css | ✓ | | | `vscode-css-language-server` |
| dart | ✓ | | ✓ | `dart` |
| dockerfile | ✓ | | | `docker-langserver` |
+| ejs | ✓ | | | |
| elixir | ✓ | | | `elixir-ls` |
| elm | ✓ | | | `elm-language-server` |
+| erb | ✓ | | | |
| erlang | ✓ | | | `erlang_ls` |
| fish | ✓ | ✓ | ✓ | |
| git-commit | ✓ | | | |
diff --git a/languages.toml b/languages.toml
index e80ca280..13c34e01 100644
--- a/languages.toml
+++ b/languages.toml
@@ -1088,3 +1088,25 @@ language-server = { command = "sourcekit-lsp" }
[[grammar]]
name = "swift"
source = { git = "https://github.com/Dispersia/tree-sitter-swift", rev = "e75240f89bb3bfd3396155859ae364e5c58d7377" }
+
+[[language]]
+name = "erb"
+scope = "text.html.erb"
+injection-regex = "erb"
+file-types = ["erb"]
+roots = []
+indent = { tab-width = 2, unit = " " }
+grammar = "embedded-template"
+
+[[language]]
+name = "ejs"
+scope = "text.html.ejs"
+injection-regex = "ejs"
+file-types = ["ejs"]
+roots = []
+indent = { tab-width = 2, unit = " " }
+grammar = "embedded-template"
+
+[[grammar]]
+name = "embedded-template"
+source = { git = "https://github.com/tree-sitter/tree-sitter-embedded-template", rev = "d21df11b0ecc6fd211dbe11278e92ef67bd17e97" }
diff --git a/runtime/queries/ejs/highlights.scm b/runtime/queries/ejs/highlights.scm
new file mode 100644
index 00000000..0bf76a7d
--- /dev/null
+++ b/runtime/queries/ejs/highlights.scm
@@ -0,0 +1,12 @@
+(comment_directive) @comment
+
+[
+ "<%#"
+ "<%"
+ "<%="
+ "<%_"
+ "<%-"
+ "%>"
+ "-%>"
+ "_%>"
+] @keyword
diff --git a/runtime/queries/ejs/injections.scm b/runtime/queries/ejs/injections.scm
new file mode 100644
index 00000000..e612a936
--- /dev/null
+++ b/runtime/queries/ejs/injections.scm
@@ -0,0 +1,7 @@
+((content) @injection.content
+ (#set! injection.language "html")
+ (#set! injection.combined))
+
+((code) @injection.content
+ (#set! injection.language "javascript")
+ (#set! injection.combined))
diff --git a/runtime/queries/erb/highlights.scm b/runtime/queries/erb/highlights.scm
new file mode 100644
index 00000000..38830615
--- /dev/null
+++ b/runtime/queries/erb/highlights.scm
@@ -0,0 +1 @@
+; inherits: ejs
diff --git a/runtime/queries/erb/injections.scm b/runtime/queries/erb/injections.scm
new file mode 100644
index 00000000..2824f7a0
--- /dev/null
+++ b/runtime/queries/erb/injections.scm
@@ -0,0 +1,7 @@
+((content) @injection.content
+ (#set! injection.language "html")
+ (#set! injection.combined))
+
+((code) @injection.content
+ (#set! injection.language "ruby")
+ (#set! injection.combined))