Skip to content

Commit 6971397

Browse files
Switch svelte treesitter and update queries (#14343)
1 parent 2dddace commit 6971397

File tree

6 files changed

+85
-86
lines changed

6 files changed

+85
-86
lines changed

languages.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ language-servers = [ "svelteserver" ]
14921492

14931493
[[grammar]]
14941494
name = "svelte"
1495-
source = { git = "https://github.com/Himujjal/tree-sitter-svelte", rev = "60ea1d673a1a3eeeb597e098d9ada9ed0c79ef4b" }
1495+
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-svelte", rev = "ae5199db47757f785e43a14b332118a5474de1a2" }
14961496

14971497
[[language]]
14981498
name = "vue"

runtime/queries/svelte/folds.scm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; inherits: html
2+
3+
[
4+
(if_statement)
5+
(else_if_block)
6+
(else_block)
7+
(each_statement)
8+
(await_statement)
9+
(then_block)
10+
(catch_block)
11+
(key_statement)
12+
(snippet_statement)
13+
] @fold
Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,38 @@
1-
; Special identifiers
2-
;--------------------
1+
; inherits: html
32

4-
(tag_name) @tag
5-
(attribute_name) @variable.other.member
6-
(erroneous_end_tag_name) @error
7-
(comment) @comment
3+
(raw_text) @none
84

9-
; TODO:
10-
((element (start_tag (tag_name) @_tag) (text) @markup.heading)
11-
(#match? @_tag "^(h[0-9]|title)$"))
12-
13-
((element (start_tag (tag_name) @_tag) (text) @markup.bold)
14-
(#match? @_tag "^(strong|b)$"))
15-
16-
((element (start_tag (tag_name) @_tag) (text) @markup.italic)
17-
(#match? @_tag "^(em|i)$"))
18-
19-
; ((element (start_tag (tag_name) @_tag) (text) @markup.strike)
20-
; (#match? @_tag "^(s|del)$"))
21-
22-
((element (start_tag (tag_name) @_tag) (text) @markup.underline)
23-
(#eq? @_tag "u"))
24-
25-
((element (start_tag (tag_name) @_tag) (text) @markup.inline)
26-
(#match? @_tag "^(code|kbd)$"))
27-
28-
((element (start_tag (tag_name) @_tag) (text) @markup.link.url)
29-
(#eq? @_tag "a"))
5+
[
6+
"as"
7+
"key"
8+
"html"
9+
"debug"
10+
"snippet"
11+
"render"
12+
] @keyword
3013

31-
((attribute
32-
(attribute_name) @_attr
33-
(quoted_attribute_value (attribute_value) @markup.link.url))
34-
(#match? @_attr "^(href|src)$"))
14+
"const" @keyword.storage.modifier
3515

3616
[
37-
(attribute_value)
38-
(quoted_attribute_value)
39-
] @string
17+
"if"
18+
"else if"
19+
"else"
20+
"then"
21+
"await"
22+
] @keyword.control.conditional
4023

41-
[
42-
(text)
43-
(raw_text_expr)
44-
] @none
24+
"each" @keyword.control.repeat
4525

46-
[
47-
(special_block_keyword)
48-
(then)
49-
(as)
50-
] @keyword
26+
"catch" @keyword.control.exception
5127

5228
[
5329
"{"
5430
"}"
55-
] @punctuation.brackets
56-
57-
"=" @operator
31+
] @punctuation.bracket
5832

5933
[
60-
"<"
61-
">"
62-
"</"
63-
"/>"
6434
"#"
6535
":"
6636
"/"
6737
"@"
68-
] @punctuation.definition.tag
38+
] @punctuation.delimiter

runtime/queries/svelte/indents.scm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
[
22
(element)
3+
(start_tag)
34
(if_statement)
5+
(else_if_block)
6+
(else_block)
7+
(then_block)
48
(each_statement)
9+
(key_statement)
10+
(snippet_statement)
511
(await_statement)
6-
(script_element)
712
(style_element)
13+
(script_element)
14+
(expression)
815
] @indent
916

1017
[
1118
(end_tag)
12-
(else_statement)
13-
(if_end_expr)
14-
(each_end_expr)
15-
(await_end_expr)
16-
">"
17-
"/>"
18-
] @outdent
19+
(if_end)
20+
(each_end)
21+
(await_end)
22+
(key_end)
23+
(snippet_end)
24+
] @outdent
Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
1-
; injections.scm
2-
; --------------
31
((style_element
42
(raw_text) @injection.content)
53
(#set! injection.language "css"))
64

75
((style_element
8-
(start_tag
9-
(attribute
10-
(attribute_name) @_attr
11-
(quoted_attribute_value (attribute_value) @_lang)))
12-
(raw_text) @injection.content)
6+
(start_tag
7+
(attribute
8+
(attribute_name) @_attr
9+
(quoted_attribute_value
10+
(attribute_value) @_lang)))
11+
(raw_text) @injection.content)
1312
(#eq? @_attr "lang")
14-
(#match? @_lang "scss")
13+
(#any-of? @_lang "scss" "postcss" "less")
1514
(#set! injection.language "scss"))
1615

17-
((attribute
18-
(attribute_name) @_attr
19-
(quoted_attribute_value (attribute_value) @css))
20-
(#eq? @_attr "style"))
16+
((svelte_raw_text) @injection.content
17+
(#set! injection.language "javascript"))
2118

22-
(
23-
(script_element
24-
(start_tag
25-
(attribute
26-
(quoted_attribute_value (attribute_value) @_lang)))
27-
(raw_text) @injection.content)
28-
(#match? @_lang "(ts|typescript)")
29-
(#set! injection.language "typescript")
30-
)
19+
((script_element
20+
(start_tag
21+
(attribute
22+
(attribute_name) @_attr
23+
(quoted_attribute_value
24+
(attribute_value) @_lang)))
25+
(raw_text) @injection.content)
26+
(#eq? @_attr "lang")
27+
(#any-of? @_lang "ts" "typescript")
28+
(#set! injection.language "typescript"))
3129

3230
((script_element
31+
(start_tag
32+
(attribute
33+
(attribute_name) @_attr
34+
(quoted_attribute_value
35+
(attribute_value) @_lang)))
3336
(raw_text) @injection.content)
37+
(#eq? @_attr "lang")
38+
(#any-of? @_lang "js" "javascript")
3439
(#set! injection.language "javascript"))
3540

36-
((raw_text_expr) @injection.content
37-
(#set! injection.language "javascript"))
38-
39-
((comment) @injection.content
40-
(#set! injection.language "comment"))
41+
((element
42+
(start_tag
43+
(attribute
44+
(attribute_name) @_attr
45+
(quoted_attribute_value
46+
(attribute_value) @injection.language)))
47+
(text) @injection.content)
48+
(#eq? @_attr "lang")
49+
(#eq? @injection.language "pug"))

runtime/queries/svelte/locals.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits: html

0 commit comments

Comments
 (0)