Skip to content

Commit 4a36c12

Browse files
c0rydoraspostsolar
authored andcommitted
Add support for ember.js templates (helix-editor#9902)
* feat: add support for ember .hbs (glimmer) templates * adjust highlights to helix * highlight this correctly in block statements * correctly highlight attributes * correctly highlight hash_pair * add newline to highlights.scm * refactor: use #any-of and #eq instead of #match * chore: add newline to languages.toml
1 parent 9bf6da3 commit 4a36c12

3 files changed

Lines changed: 119 additions & 1 deletion

File tree

book/src/generated/lang-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
| git-ignore || | | |
6161
| git-rebase || | | |
6262
| gleam ||| | `gleam` |
63+
| glimmer || | | `ember-language-server` |
6364
| glsl |||| |
6465
| gn || | | |
6566
| go |||| `gopls`, `golangci-lint-langserver` |

languages.toml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] }
100100
typst-lsp = { command = "typst-lsp" }
101101
pkgbuild-language-server = { command = "pkgbuild-language-server" }
102102
helm_ls = { command = "helm_ls", args = ["serve"] }
103+
ember-language-server = { command = "ember-language-server", args = ["--stdio"] }
103104

104105
[language-server.ansible-language-server]
105106
command = "ansible-language-server"
@@ -3390,4 +3391,26 @@ scope = "source.helm"
33903391
roots = ["Chart.yaml"]
33913392
comment-token = "#"
33923393
language-servers = ["helm_ls"]
3393-
file-types = [ { glob = "templates/*.yaml" }, { glob = "templates/_helpers.tpl"}, { glob = "templates/NOTES.txt" } ]
3394+
file-types = [ { glob = "templates/*.yaml" }, { glob = "templates/_helpers.tpl"}, { glob = "templates/NOTES.txt" } ]
3395+
3396+
[[language]]
3397+
name = "glimmer"
3398+
scope = "source.glimmer"
3399+
injection-regex = "hbs"
3400+
file-types = [{ glob = "{app,addon}/{components,templates}/*.hbs" }]
3401+
block-comment-tokens = { start = "{{!", end = "}}" }
3402+
roots = ["package.json", "ember-cli-build.js"]
3403+
grammar = "glimmer"
3404+
language-servers = ["ember-language-server"]
3405+
formatter = { command = "prettier", args = ['--parser', 'glimmer'] }
3406+
3407+
[language.auto-pairs]
3408+
'"' = '"'
3409+
'{' = '}'
3410+
'(' = ')'
3411+
'<' = '>'
3412+
"'" = "'"
3413+
3414+
[[grammar]]
3415+
name = "glimmer"
3416+
source = { git = "https://github.com/ember-tooling/tree-sitter-glimmer", rev = "5dc6d1040e8ff8978ff3680e818d85447bbc10aa" }
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
; === Tag Names ===
2+
3+
; Tags that start with a lower case letter are HTML tags
4+
; We'll also use this highlighting for named blocks (which start with `:`)
5+
((tag_name) @tag
6+
(#match? @tag "^(:)?[a-z]"))
7+
; Tags that start with a capital letter are Glimmer components
8+
((tag_name) @constructor
9+
(#match? @constructor "^[A-Z]"))
10+
11+
(attribute_name) @attribute
12+
13+
(string_literal) @string
14+
(number_literal) @constant.numeric.integer
15+
(boolean_literal) @constant.builtin.boolean
16+
17+
(concat_statement) @string
18+
19+
; === Block Statements ===
20+
21+
; Highlight the brackets
22+
(block_statement_start) @punctuation.delimiter
23+
(block_statement_end) @punctuation.delimiter
24+
25+
; Highlight `if`/`each`/`let`
26+
(block_statement_start path: (identifier) @keyword.control.conditional)
27+
(block_statement_end path: (identifier) @keyword.control.conditional)
28+
((mustache_statement (identifier) @keyword.control.conditional)
29+
(#eq? @keyword.control.conditional "else"))
30+
31+
; == Mustache Statements ===
32+
33+
; Hightlight the whole statement, to color brackets and separators
34+
(mustache_statement) @punctuation.delimiter
35+
36+
; An identifier in a mustache expression is a variable
37+
((mustache_statement [
38+
(path_expression (identifier) @variable)
39+
(identifier) @variable
40+
])
41+
(#not-any-of? @variable "yield" "outlet" "this" "else"))
42+
; As are arguments in a block statement
43+
((block_statement_start argument: [
44+
(path_expression (identifier) @variable)
45+
(identifier) @variable
46+
])
47+
(#not-eq? @variable "this"))
48+
; As is an identifier in a block param
49+
(block_params (identifier) @variable)
50+
; As are helper arguments
51+
((helper_invocation argument: [
52+
(path_expression (identifier) @variable)
53+
(identifier) @variable
54+
])
55+
(#not-eq? @variable "this"))
56+
; `this` should be highlighted as a built-in variable
57+
((identifier) @variable.builtin
58+
(#eq? @variable.builtin "this"))
59+
60+
; If the identifier is just "yield" or "outlet", it's a keyword
61+
((mustache_statement (identifier) @keyword.control.return)
62+
(#any-of? @keyword.control.return "yield" "outlet"))
63+
64+
; Helpers are functions
65+
((helper_invocation helper: [
66+
(path_expression (identifier) @function)
67+
(identifier) @function
68+
])
69+
(#not-any-of? @function "if" "yield"))
70+
71+
((helper_invocation helper: (identifier) @keyword.control.conditional)
72+
(#any-of? @keyword.control.conditional "if" "yield"))
73+
74+
(hash_pair key: (identifier) @variable)
75+
(hash_pair value: (identifier) @variable)
76+
(hash_pair [
77+
(path_expression (identifier) @variable)
78+
(identifier) @variable
79+
])
80+
81+
(comment_statement) @comment
82+
83+
(attribute_node "=" @operator)
84+
85+
(block_params "as" @keyword.control)
86+
(block_params "|" @operator)
87+
88+
[
89+
"<"
90+
">"
91+
"</"
92+
"/>"
93+
] @punctuation.delimiter
94+

0 commit comments

Comments
 (0)