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

languages: add svelte support #733

Merged
merged 2 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@
path = helix-syntax/languages/tree-sitter-zig
url = https://github.com/maxxnino/tree-sitter-zig
shallow = true
[submodule "helix-syntax/languages/tree-sitter-svelte"]
path = helix-syntax/languages/tree-sitter-svelte
url = https://github.com/Himujjal/tree-sitter-svelte
shallow = true
9 changes: 9 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ roots = []
comment-token = "--"
indent = { tab-width = 2, unit = " " }

[[language]]
name = "svelte"
scope = "source.svelte"
injection-regex = "svelte"
file-types = ["svelte"]
roots = []
indent = { tab-width = 2, unit = " " }
language-server = { command = "svelteserver", args = ["--stdio"] }

[[language]]
name = "yaml"
scope = "source.yaml"
Expand Down
68 changes: 68 additions & 0 deletions runtime/queries/svelte/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
; Special identifiers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these need to be converted into Helix's scopes: https://docs.helix-editor.com/themes.html

Copy link
Member

@kirawi kirawi Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archseer Do we want to also add the none scope?

;--------------------

; TODO:
((element (start_tag (tag_name) @_tag) (text) @markup.heading)
(#match? @_tag "^(h[0-9]|title)$"))

((element (start_tag (tag_name) @_tag) (text) @markup.bold)
(#match? @_tag "^(strong|b)$"))

((element (start_tag (tag_name) @_tag) (text) @markup.italic)
(#match? @_tag "^(em|i)$"))

; ((element (start_tag (tag_name) @_tag) (text) @markup.strike)
; (#match? @_tag "^(s|del)$"))

((element (start_tag (tag_name) @_tag) (text) @markup.underline)
(#eq? @_tag "u"))

((element (start_tag (tag_name) @_tag) (text) @markup.inline)
(#match? @_tag "^(code|kbd)$"))

((element (start_tag (tag_name) @_tag) (text) @markup.underline.link)
(#eq? @_tag "a"))

((attribute
(attribute_name) @_attr
(quoted_attribute_value (attribute_value) @markup.undeline.link))
(#match? @_attr "^(href|src)$"))

(tag_name) @tag
(attribute_name) @property
(erroneous_end_tag_name) @error
(comment) @comment

[
(attribute_value)
(quoted_attribute_value)
] @string

[
(text)
(raw_text_expr)
] @none

[
(special_block_keyword)
(then)
(as)
] @keyword

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

"=" @operator

[
"<"
">"
"</"
"/>"
"#"
":"
"/"
"@"
] @punctuation.definition.tag
18 changes: 18 additions & 0 deletions runtime/queries/svelte/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
indent = [
"element"
"if_statement"
"each_statement"
"await_statement"
]

outdent = [
"end_tag"
"else_statement"
"if_end_expr"
"each_end_expr"
"await_end_expr"
">"
"/>"
]

ignore = "comment"
30 changes: 30 additions & 0 deletions runtime/queries/svelte/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; injections.scm
; --------------
archseer marked this conversation as resolved.
Show resolved Hide resolved
((style_element
(raw_text) @injection.content)
(#set! injection.language "css"))

((attribute
(attribute_name) @_attr
(quoted_attribute_value (attribute_value) @css))
(#eq? @_attr "style"))

((script_element
(raw_text) @injection.content)
(#set! injection.language "javascript"))

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

(
(script_element
(start_tag
(attribute
(quoted_attribute_value (attribute_value) @_lang)))
(raw_text) @injection.content)
(#match? @_lang "(ts|typescript)")
(#set! injection.language "typescript")
)

(comment) @comment