Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte: Migrate to tree-sitter-grammars/tree-sitter-svelte #17529

Merged
merged 26 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fb61847
Revert to earlier commit
AlbertMarashi Sep 5, 2024
b1adc74
Merge branch 'main' of https://github.com/AlbertMarashi/zed
AlbertMarashi Sep 5, 2024
26d7800
closes #17310
AlbertMarashi Sep 5, 2024
b1cf900
migration to tree-sitter-grammer's svelte
AlbertMarashi Sep 7, 2024
81626e2
update svelte docs
AlbertMarashi Sep 9, 2024
7e3b1cb
fix autoclosing issues and some other improvements
AlbertMarashi Sep 9, 2024
d5d2ff4
Remove some unused comments
AlbertMarashi Sep 9, 2024
a2c99c1
Merge branch 'main' into main
AlbertMarashi Sep 9, 2024
6ced9a1
fix possible docs issue
AlbertMarashi Sep 9, 2024
c9bcb41
make the json example use jsonc
AlbertMarashi Sep 9, 2024
48a71ba
Add highlighting for as keyword in each blocks
AlbertMarashi Sep 11, 2024
88acddc
See if this fixes docs failing issue
AlbertMarashi Sep 11, 2024
31c730a
Maybe it's the json comments
AlbertMarashi Sep 11, 2024
ece8367
I give up, maintainer plz help
AlbertMarashi Sep 11, 2024
abb9fac
remove duplicate line
AlbertMarashi Sep 11, 2024
dd14ec2
disable generics syntax highlighting
AlbertMarashi Sep 11, 2024
545b7f2
Merge branch 'main' of https://github.com/AlbertMarashi/zed
AlbertMarashi Sep 11, 2024
46d06c1
Revert version bump
maxdeviant Sep 12, 2024
e23928b
Add back mistakingly removed tailwind code
AlbertMarashi Sep 13, 2024
e006c5d
highlight snippet names
AlbertMarashi Sep 13, 2024
27563a4
rename to attribute_modifier per tree-sitter pr
AlbertMarashi Sep 13, 2024
9b479c0
update git commit version
AlbertMarashi Sep 13, 2024
243fb3d
Merge branch 'main' of https://github.com/AlbertMarashi/zed
AlbertMarashi Sep 13, 2024
645d596
Merge branch 'main' into pr/17529
maxdeviant Sep 17, 2024
42b4053
Update docs
maxdeviant Sep 17, 2024
ae6627e
Remove unneeded comment
maxdeviant Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions extensions/svelte/extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ name = "Svelte Language Server"
language = "Svelte"

[grammars.svelte]
repository = "https://github.com/Himujjal/tree-sitter-svelte"
commit = "b08d070e303d2a385d6d0ab3add500f8fa514443"
repository = "https://github.com/tree-sitter-grammars/tree-sitter-svelte"
# old
# commit = "038dea960b58a88d3a8e916e81399d6bfed50ef8"
# commit = "1a7bf64127e39cc1beda71858778e7874b1c4a10"
commit = "6fe714f0c9026a986b916bf39c1021ffcb1e995b"
8 changes: 8 additions & 0 deletions extensions/svelte/languages/svelte/brackets.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
("<" @open ">" @close)
("{" @open "}" @close)
("(" @open ")" @close)
("'" @open "'" @close)
("\"" @open "\"" @close)

; ("[" @open "]" @close)
; ("`" @open "`" @close)
19 changes: 3 additions & 16 deletions extensions/svelte/languages/svelte/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@ name = "Svelte"
grammar = "svelte"
path_suffixes = ["svelte"]
block_comment = ["<!-- ", " -->"]
autoclose_before = ";:.,=}])>"
brackets = [
{ start = "{", end = "}", close = true, newline = true },
{ start = "[", end = "]", close = true, newline = true },
{ start = "(", end = ")", close = true, newline = true },
{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
{ start = "`", end = "`", close = true, newline = false, not_in = ["string"] },
{ start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]
AlbertMarashi marked this conversation as resolved.
Show resolved Hide resolved
scope_opt_in_language_servers = ["tailwindcss-language-server"]

# Not sure what these are for, so will await feedback
# autoclose_before = ";:.,=}])>"
prettier_parser_name = "svelte"
prettier_plugins = ["prettier-plugin-svelte"]

[overrides.string]
word_characters = ["-"]
opt_into_language_servers = ["tailwindcss-language-server"]
AlbertMarashi marked this conversation as resolved.
Show resolved Hide resolved
105 changes: 73 additions & 32 deletions extensions/svelte/languages/svelte/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,50 +1,91 @@
; Special identifiers
;--------------------
; ; Special identifiers
; ;--------------------

; Treat capitalized tag names as constructors and types
((tag_name) @type
(#match? @type "^[A-Z]"))
; comments
(comment) @comment

; Regular (lowercase) tag names
((tag_name) @tag
(#match? @tag "^[a-z]"))
; property attribute
; TODO: we need to break this down in the source repository to distinguish between
; - directives, eg: foo:bar="baz" and foo="baz"
; - possibly --props
(attribute_name) @attribute

; TODO:
(attribute_name) @property
(erroneous_end_tag_name) @keyword
(comment) @comment
; Style component attributes as @property
(start_tag
(
(tag_name) @_tag_name
(#match? @_tag_name "^[A-Z]")
)
(attribute
(attribute_name) @property
)
)

[
(attribute_value)
(quoted_attribute_value)
] @string
(self_closing_tag
(
(tag_name) @_tag_name
(#match? @_tag_name "^[A-Z]")
)
(attribute
(attribute_name) @property
)
)

[
(text)
(raw_text_expr)
(raw_text_each)
] @none

; style elements starting with lowercase letters as tags
(
(tag_name) @tag
(#match? @tag "^[a-z]")
)

; style elements starting with uppercase letters as components (types)
; Also valid might be to treat them as constructors
(
(tag_name) @tag @tag.component.type.constructor
(#match? @tag "^[A-Z]")
)

[
(special_block_keyword)
(then)
(as)
] @keyword
"<"
">"
"</"
"/>"
] @tag.punctuation.bracket


[
"{"
"}"
] @punctuation.bracket

"=" @operator

[
"<"
">"
"</"
"/>"
"@"
"#"
":"
"/"
"@"
] @tag.delimiter
] @tag.punctuation.special

"=" @operator


; Treating (if, each, ...) as a keyword inside of blocks
; like {#if ...} or {#each ...}
(block_start_tag
tag: _ @tag.keyword
)

(block_tag
tag: _ @tag.keyword
)

(block_end_tag
tag: _ @tag.keyword
)

(expression_tag
tag: _ @tag.keyword
)

; Style quoted string attribute values
(quoted_attribute_value) @string
125 changes: 59 additions & 66 deletions extensions/svelte/languages/svelte/injections.scm
Original file line number Diff line number Diff line change
@@ -1,74 +1,67 @@
; injections.scm
; --------------
; ; injections.scm
; ; --------------

; match script tags without a lang tag
((script_element
(start_tag
(attribute
(attribute_name) @_name)*)
(raw_text) @content)
(#not-eq? @_name "lang")
(#set! "language" "javascript"))
; Match script tags with a lang attribute
(script_element
(start_tag
(attribute
(attribute_name) @_attr_name
(#eq? @_attr_name "lang")
(quoted_attribute_value
(attribute_value) @language
)
)
)
(raw_text) @content
)

; match javascript
((script_element
(start_tag
(attribute
(attribute_name) @_name
(quoted_attribute_value (attribute_value) @_value)))
(raw_text) @content)
(#eq? @_name "lang")
(#eq? @_value "js")
(#set! "language" "javascript"))
; Match script tags without a lang attribute
(script_element
(start_tag
(attribute
(attribute_name) @_attr_name
)*
)
(raw_text) @content
(#not-any-of? @_attr_name "lang")
(#set! language "javascript")
)

; match typescript
((script_element
(start_tag
(attribute
(attribute_name) @_name
(quoted_attribute_value (attribute_value) @_value)))
(raw_text) @content)
(#eq? @_name "lang")
(#eq? @_value "ts")
(#set! "language" "typescript"))

(style_element
(raw_text) @content
(#set! "language" "css"))

; match style tags without a lang tag
((style_element
(start_tag
(attribute
(attribute_name) @_name)*)
(raw_text) @content)
(#not-eq? @_name "lang")
(#set! "language" "css"))
; Mark everything as typescript because it's
; a more generic superset of javascript
; Not sure if it's possible to somehow refer to the
; script's language attribute here.
((svelte_raw_text) @content
(#set! "language" "ts")
)

; match css
((style_element
(start_tag
(attribute
(attribute_name) @_name
(quoted_attribute_value (attribute_value) @_value)))
(raw_text) @content)
(#eq? @_name "lang")
(#eq? @_value "css")
(#set! "language" "css"))
; Match style tags with a lang attribute
(style_element
(start_tag
(attribute
(attribute_name) @_attr_name
(#eq? @_attr_name "lang")
(quoted_attribute_value
(attribute_value) @language
)
)
)
(raw_text) @content
)

; match scss
((style_element
(start_tag
(attribute
(attribute_name) @_name
(quoted_attribute_value (attribute_value) @_value)))
(raw_text) @content)
(#eq? @_name "lang")
(#eq? @_value "scss")
(#set! "language" "scss"))
; Match style tags without a lang attribute
(style_element
(start_tag
(attribute
(attribute_name) @_attr_name
)*
)
(raw_text) @content
(#not-any-of? @_attr_name "lang")
(#set! language "css")
)

((raw_text_expr) @content
(#set! "language" "javascript"))

((raw_text_each) @content
(#set! "language" "javascript"))
; Downstream TODO: Style highlighting for `style:background="red"` and `style="background: red"` strings
AlbertMarashi marked this conversation as resolved.
Show resolved Hide resolved
; Downstream TODO: Style component comments as markdown
69 changes: 69 additions & 0 deletions extensions/svelte/languages/svelte/outline.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

(script_element
(start_tag) @name
(raw_text) @context @item
)

(script_element
(end_tag) @name @item
)

(style_element
(start_tag) @name
(raw_text) @context
) @item


(document) @item

(comment) @annotation

(if_statement
(if_start) @name
) @item

(else_block
(else_start) @name
) @item

(else_if_block
(else_if_start) @name
) @item

(element
(start_tag) @name
) @item

(element
(self_closing_tag) @name
) @item


; (if_end) @name @item

(each_statement
(each_start) @name
) @item


(snippet_statement
(snippet_start) @name
) @item

(snippet_end) @name @item

(html_tag) @name @item

(const_tag) @name @item

(await_statement
(await_start) @name
) @item

(then_block
(then_start) @name
) @item

(catch_block
(catch_start) @name
) @item
12 changes: 7 additions & 5 deletions extensions/svelte/languages/svelte/overrides.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(comment) @comment

[
(raw_text)
(attribute_value)
(quoted_attribute_value)
] @string
AlbertMarashi marked this conversation as resolved.
Show resolved Hide resolved

; Question: What are these for?
; [
; (raw_text)
; (attribute_value)
; (quoted_attribute_value)
; ] @string