From a937a67222dac20bf0db94a7c8bba0c34a0b6b08 Mon Sep 17 00:00:00 2001 From: Arjun31415 Date: Tue, 15 Nov 2022 12:49:55 +0530 Subject: [PATCH] added queries for svelte (#1702) --- CHANGELOG.md | 1 + lapce-core/queries/svelte/highlights.scm | 110 +++++++++++++++++++++++ lapce-core/queries/svelte/indents.scm | 24 +++++ lapce-core/queries/svelte/injections.scm | 32 +++++++ lapce-core/src/language.rs | 4 +- 5 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 lapce-core/queries/svelte/highlights.scm create mode 100644 lapce-core/queries/svelte/indents.scm create mode 100644 lapce-core/queries/svelte/injections.scm diff --git a/CHANGELOG.md b/CHANGELOG.md index 34deaacf..f50aa96b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Features/Changes +- [#1702](https://github.com/lapce/lapce/pull/1702) Improved svelte treesitter queries ### Bug Fixes diff --git a/lapce-core/queries/svelte/highlights.scm b/lapce-core/queries/svelte/highlights.scm new file mode 100644 index 00000000..2e30815f --- /dev/null +++ b/lapce-core/queries/svelte/highlights.scm @@ -0,0 +1,110 @@ +; src: https://github.com/helix-editor/helix/blob/master/runtime/queries/svelte/highlights.scm +; licence: https://github.com/helix-editor/helix/blob/master/LICENSE +; spdx: MPL-2.0 + +(tag_name) @tag +(erroneous_end_tag_name) @error +(comment) @comment +(attribute_name) @tag.attribute +(attribute + (quoted_attribute_value) @string) +(text) @text @spell + +((element (start_tag (tag_name) @_tag) (text) @text.title) + (#match? @_tag "^(h[0-9]|title)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.strong) + (#match? @_tag "^(strong|b)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.emphasis) + (#match? @_tag "^(em|i)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.strike) + (#match? @_tag "^(s|del)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.underline) + (#eq? @_tag "u")) + +((element (start_tag (tag_name) @_tag) (text) @text.literal) + (#match? @_tag "^(code|kbd)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.uri) + (#eq? @_tag "a")) + +((attribute + (attribute_name) @_attr + (quoted_attribute_value (attribute_value) @text.uri)) + (#match? @_attr "^(href|src)$")) + +[ + "<" + ">" + "" +] @tag.delimiter + +"=" @operator +((element (start_tag (tag_name) @_tag) (text) @text.title) + (#match? @_tag "^(h[0-9]|title)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.strong) + (#match? @_tag "^(strong|b)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.emphasis) + (#match? @_tag "^(em|i)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.strike) + (#match? @_tag "^(s|del)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.underline) + (#eq? @_tag "u")) + +((element (start_tag (tag_name) @_tag) (text) @text.literal) + (#match? @_tag "^(code|kbd)$")) + +((element (start_tag (tag_name) @_tag) (text) @text.uri) + (#eq? @_tag "a")) + +((attribute + (attribute_name) @_attr + (quoted_attribute_value (attribute_value) @text.uri)) + (#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.bracket + +"=" @operator + +[ + "<" + ">" + "" + "#" + ":" + "/" + "@" +] @tag.delimiter diff --git a/lapce-core/queries/svelte/indents.scm b/lapce-core/queries/svelte/indents.scm new file mode 100644 index 00000000..716a3f23 --- /dev/null +++ b/lapce-core/queries/svelte/indents.scm @@ -0,0 +1,24 @@ +;src: https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/svelte/indents.scm +;licence https://github.com/nvim-treesitter/nvim-treesitter/blob/master/LICENSE +; spdx: Apache-2.0 + +[ + (element) + (if_statement) + (each_statement) + (await_statement) + (script_element) + (style_element) +] @indent + +[ + (end_tag) + (else_statement) + (if_end_expr) + (each_end_expr) + (await_end_expr) + ">" + "/>" +] @branch + +(comment) @ignore diff --git a/lapce-core/queries/svelte/injections.scm b/lapce-core/queries/svelte/injections.scm new file mode 100644 index 00000000..f24f89bc --- /dev/null +++ b/lapce-core/queries/svelte/injections.scm @@ -0,0 +1,32 @@ +; src: https://github.com/helix-editor/helix/blob/master/runtime/queries/svelte/injections.scm +; licence: https://github.com/helix-editor/helix/blob/master/LICENSE +; spdx: MPL-2.0 + +((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) @injection.content + (#set! injection.language "comment")) diff --git a/lapce-core/src/language.rs b/lapce-core/src/language.rs index f58f5a11..164e8848 100644 --- a/lapce-core/src/language.rs +++ b/lapce-core/src/language.rs @@ -733,8 +733,8 @@ pub enum LapceLanguage { SyntaxProperties { id: LapceLanguage::Svelte, language: tree_sitter_svelte::language, - highlight: tree_sitter_svelte::HIGHLIGHT_QUERY, - injection: Some(tree_sitter_svelte::INJECTION_QUERY), + highlight: include_str!("../queries/svelte/highlights.scm"), + injection: Some(include_str!("../queries/svelte/injections.scm")), comment: "//", indent: " ", code_lens: (DEFAULT_CODE_LENS_LIST, DEFAULT_CODE_LENS_IGNORE_LIST),