on master help sign in
languages: add templ (#8540)
commit764715a6c069754b852ed9e8d98aaf7efd88abe6 authorrsteube <rsteube@users.noreply.github.com> dateSat 21 Oct 2023, 14:15 (3 years ago) parent8d44459
4 files changed+118
book/src/generated/lang-support.md+1 languages.toml+14 runtime/queries/templ/highlights.scm+99 runtime/queries/templ/injections.scm+4
book/src/generated/lang-support.md+1
@@ -155,6 +155,7 @@
155155| t32 | ✓ | | | |
156156| tablegen | ✓ | ✓ | ✓ | |
157157| task | ✓ | | | |
158+| templ | ✓ | | | `templ` |
158159| tfvars | ✓ | | ✓ | `terraform-ls` |
159160| todotxt | ✓ | | | |
160161| toml | ✓ | | | `taplo` |
languages.toml+14
@@ -74,6 +74,7 @@ svlangserver = { command = "svlangserver", args = [] }
7474swipl = { command = "swipl", args = [ "-g", "use_module(library(lsp_server))", "-g", "lsp_server:main", "-t", "halt", "--", "stdio" ] }
7575tailwindcss-ls = { command = "tailwindcss-language-server", args = ["--stdio"] }
7676taplo = { command = "taplo", args = ["lsp", "stdio"] }
77+templ = { command = "templ", args = ["lsp"] }
7778terraform-ls = { command = "terraform-ls", args = ["serve"] }
7879texlab = { command = "texlab" }
7980vala-language-server = { command = "vala-language-server" }
@@ -2998,3 +2999,16 @@ roots = []
29982999[[grammar]]
29993000name = "gemini"
30003001source = { git = "https://git.sr.ht/~sfr/tree-sitter-gemini", rev = "3cc5e4bdf572d5df4277fc2e54d6299bd59a54b3" }
3002+
3003+[[language]]
3004+name = "templ"
3005+scope = "source.templ"
3006+file-types = ["templ"]
3007+roots = ["go.work", "go.mod"]
3008+comment-token = "//"
3009+indent = { tab-width = 2, unit = " " }
3010+language-servers = [ "templ" ]
3011+
3012+[[grammar]]
3013+name = "templ"
3014+source = { git = "https://github.com/vrischmann/tree-sitter-templ", rev = "ea56ac0655243490a4929a988f4eaa91dfccc995" }
runtime/queries/templ/highlights.scmnew file+99
@@ -0,0 +1,99 @@
1+(package_identifier) @namespace
2+
3+(parameter_declaration (identifier) @variable.parameter)
4+(variadic_parameter_declaration (identifier) @variable.parameter)
5+
6+(function_declaration
7+ name: (identifier) @function)
8+
9+(type_spec name: (type_identifier) @type)
10+(type_identifier) @type
11+(field_identifier) @variable.other.member
12+(identifier) @variable
13+
14+; Function calls
15+
16+(call_expression
17+ function: (identifier) @function)
18+
19+(call_expression
20+ function: (selector_expression
21+ field: (field_identifier) @function))
22+
23+;
24+; These are Templ specific
25+;
26+
27+(component_declaration
28+ name: (component_identifier) @function)
29+
30+(tag_start) @tag
31+(tag_end) @tag
32+(self_closing_tag) @tag
33+(style_element) @tag
34+
35+(attribute
36+ name: (attribute_name) @attribute)
37+(attribute
38+ value: (quoted_attribute_value) @string)
39+
40+(element_text) @string.special
41+(style_element_text) @string.special
42+
43+(css_property
44+ name: (css_property_name) @attribute)
45+
46+(expression) @function.method
47+(dynamic_class_attribute_value) @function.method
48+
49+(component_import
50+ name: (component_identifier) @function)
51+
52+(component_render) @function
53+
54+[
55+ "@"
56+] @operator
57+
58+[
59+ "func"
60+ "var"
61+ "const"
62+ "templ"
63+ "css"
64+ "type"
65+ "struct"
66+ "range"
67+ "script"
68+] @keyword.storage.type
69+
70+[
71+ "return"
72+] @keyword.control.return
73+
74+[
75+ "import"
76+ "package"
77+] @keyword.control.import
78+
79+[
80+ "else"
81+ "case"
82+ "switch"
83+ "if"
84+ "default"
85+] @keyword.control.conditional
86+
87+"for" @keyword.control.repeat
88+
89+[
90+ (interpreted_string_literal)
91+ (raw_string_literal)
92+ (rune_literal)
93+] @string
94+
95+; Comments
96+
97+(comment) @comment
98+
99+(element_comment) @comment
runtime/queries/templ/injections.scmnew file+4
@@ -0,0 +1,4 @@
1+((script_block_text) @injection.content (#set! injection.language "javascript"))
2+((script_element_text) @injection.content (#set! injection.language "javascript"))
3+
4+((style_element_text) @injection.content (#set! injection.language "css"))