From 692b051b09935653befdb8f7ba8afdb640adf17b Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 12 Jun 2023 09:54:30 -0600 Subject: feat!: drop modules, general refactor and cleanup --- runtime/queries/heex/folds.scm | 6 +++++ runtime/queries/heex/highlights.scm | 54 +++++++++++++++++++++++++++++++++++++ runtime/queries/heex/indents.scm | 20 ++++++++++++++ runtime/queries/heex/injections.scm | 30 +++++++++++++++++++++ runtime/queries/heex/locals.scm | 13 +++++++++ 5 files changed, 123 insertions(+) create mode 100644 runtime/queries/heex/folds.scm create mode 100644 runtime/queries/heex/highlights.scm create mode 100644 runtime/queries/heex/indents.scm create mode 100644 runtime/queries/heex/injections.scm create mode 100644 runtime/queries/heex/locals.scm (limited to 'runtime/queries/heex') 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 %> +;

hello, tree-sitter!

+; <% 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 +; +(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 -- cgit v1.2.3-70-g09d2