aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/heex
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/heex
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/heex')
-rw-r--r--runtime/queries/heex/folds.scm6
-rw-r--r--runtime/queries/heex/highlights.scm54
-rw-r--r--runtime/queries/heex/indents.scm20
-rw-r--r--runtime/queries/heex/injections.scm30
-rw-r--r--runtime/queries/heex/locals.scm13
5 files changed, 123 insertions, 0 deletions
diff --git a/runtime/queries/heex/folds.scm b/runtime/queries/heex/folds.scm
new file mode 100644
index 000000000..88d4f17ff
--- /dev/null
+++ b/runtime/queries/heex/folds.scm
@@ -0,0 +1,6 @@
+; HEEx tags, components, and slots fold similar to HTML
+[
+ (component)
+ (tag)
+ (slot)
+] @fold
diff --git a/runtime/queries/heex/highlights.scm b/runtime/queries/heex/highlights.scm
new file mode 100644
index 000000000..e2fb01880
--- /dev/null
+++ b/runtime/queries/heex/highlights.scm
@@ -0,0 +1,54 @@
+; HEEx delimiters
+[
+ "%>"
+ "--%>"
+ "-->"
+ "/>"
+ "<!"
+ "<!--"
+ "<"
+ "<%!--"
+ "<%"
+ "<%#"
+ "<%%="
+ "<%="
+ "</"
+ "</:"
+ "<:"
+ ">"
+ "{"
+ "}"
+] @tag.delimiter
+
+; HEEx operators are highlighted as such
+"=" @operator
+
+; HEEx inherits the DOCTYPE tag from HTML
+(doctype) @constant
+
+; HEEx comments are highlighted as such
+(comment) @comment @spell
+
+; HEEx text content is treated as markup
+; (text) @none
+; HEEx tags and slots are highlighted as HTML
+[
+ (tag_name)
+ (slot_name)
+] @tag
+
+; HEEx attributes are highlighted as HTML attributes
+(attribute_name) @tag.attribute
+
+[
+ (attribute_value)
+ (quoted_attribute_value)
+] @string
+
+; HEEx components are highlighted as modules and function calls
+(component_name
+ [
+ (module) @type
+ (function) @function
+ "." @punctuation.delimiter
+ ])
diff --git a/runtime/queries/heex/indents.scm b/runtime/queries/heex/indents.scm
new file mode 100644
index 000000000..82a2f8912
--- /dev/null
+++ b/runtime/queries/heex/indents.scm
@@ -0,0 +1,20 @@
+; HEEx tags, components, and slots indent like HTML
+[
+ (component)
+ (slot)
+ (tag)
+] @indent.begin
+
+; Dedent at the end of each tag, component, and slot
+[
+ (end_component)
+ (end_slot)
+ (end_tag)
+] @indent.branch @indent.dedent
+
+; Self-closing tags and components should not change
+; indentation level of sibling nodes
+[
+ (self_closing_component)
+ (self_closing_tag)
+] @indent.auto
diff --git a/runtime/queries/heex/injections.scm b/runtime/queries/heex/injections.scm
new file mode 100644
index 000000000..4f179ee80
--- /dev/null
+++ b/runtime/queries/heex/injections.scm
@@ -0,0 +1,30 @@
+; directives are standalone tags like '<%= @x %>'
+;
+; partial_expression_values are elixir code that is part of an expression that
+; spans multiple directive nodes, so they must be combined. For example:
+; <%= if true do %>
+; <p>hello, tree-sitter!</p>
+; <% end %>
+(directive
+ [
+ (partial_expression_value)
+ (ending_expression_value)
+ ] @injection.content
+ (#set! injection.language "elixir")
+ (#set! injection.include-children)
+ (#set! injection.combined))
+
+; Regular expression_values do not need to be combined
+((directive
+ (expression_value) @injection.content)
+ (#set! injection.language "elixir"))
+
+; expressions live within HTML tags, and do not need to be combined
+; <link href={ Routes.static_path(..) } />
+(expression
+ (expression_value) @injection.content
+ (#set! injection.language "elixir"))
+
+; HEEx comments
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/heex/locals.scm b/runtime/queries/heex/locals.scm
new file mode 100644
index 000000000..cfa239e5f
--- /dev/null
+++ b/runtime/queries/heex/locals.scm
@@ -0,0 +1,13 @@
+; HEEx tags, components, and slots are references
+[
+ (component_name)
+ (slot_name)
+ (tag_name)
+] @local.reference
+
+; Create a new scope within each HEEx tag, component, and slot
+[
+ (component)
+ (slot)
+ (tag)
+] @local.scope