Unnamed repository; edit this file 'description' to name the repository.
Update tree-sitter-blade and queries (#14097)
Co-authored-by: Emran <[email protected]>
| -rw-r--r-- | book/src/generated/lang-support.md | 2 | ||||
| -rw-r--r-- | languages.toml | 2 | ||||
| -rw-r--r-- | runtime/queries/blade/folds.scm | 5 | ||||
| -rw-r--r-- | runtime/queries/blade/highlights.scm | 18 | ||||
| -rw-r--r-- | runtime/queries/blade/injections.scm | 106 | ||||
| -rw-r--r-- | runtime/queries/blade/rainbows.scm | 1 | ||||
| -rw-r--r-- | runtime/queries/blade/textobjects.scm | 1 |
7 files changed, 120 insertions, 15 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 640de2f5..3c9e503a 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -13,7 +13,7 @@ | bibtex | ✓ | | | | | `texlab` | | bicep | ✓ | | | | | `bicep-langserver` | | bitbake | ✓ | | | | | `bitbake-language-server` | -| blade | ✓ | | | | | | +| blade | ✓ | ✓ | | | ✓ | | | blueprint | ✓ | | | | | `blueprint-compiler` | | c | ✓ | ✓ | ✓ | ✓ | ✓ | `clangd` | | c-sharp | ✓ | ✓ | | ✓ | | `OmniSharp` | diff --git a/languages.toml b/languages.toml index 719cc319..6cd5d5f5 100644 --- a/languages.toml +++ b/languages.toml @@ -1185,7 +1185,7 @@ roots = ["composer.json", "index.php"] [[grammar]] name = "blade" -source = { git = "https://github.com/EmranMR/tree-sitter-blade", rev = "4c66efe1e05c639c555ee70092021b8223d2f440" } +source = { git = "https://github.com/EmranMR/tree-sitter-blade", rev = "59ce5b68e288002e3aee6cf5a379bbef21adbe6c" } [[language]] name = "twig" diff --git a/runtime/queries/blade/folds.scm b/runtime/queries/blade/folds.scm index c1711482..3977a08b 100644 --- a/runtime/queries/blade/folds.scm +++ b/runtime/queries/blade/folds.scm @@ -1,8 +1,9 @@ +; inherits: html + ((directive_start) @start (directive_end) @end.after (#set! role block)) - ((bracket_start) @start (bracket_end) @end - (#set! role block))
\ No newline at end of file + (#set! role block)) diff --git a/runtime/queries/blade/highlights.scm b/runtime/queries/blade/highlights.scm index 04a4b965..e6d27fad 100644 --- a/runtime/queries/blade/highlights.scm +++ b/runtime/queries/blade/highlights.scm @@ -1,8 +1,16 @@ -(directive) @tag -(directive_start) @tag -(directive_end) @tag +; inherits: html + +(directive) @keyword.directive +(directive_start) @keyword.directive +(directive_end) @keyword.directive (comment) @comment + +; merged with blade punctuation [ - (bracket_start) - (bracket_end) + "{{" + "}}" + "{!!" + "!!}" + "(" + ")" ] @punctuation.bracket diff --git a/runtime/queries/blade/injections.scm b/runtime/queries/blade/injections.scm index 77cf9eef..b37c18a7 100644 --- a/runtime/queries/blade/injections.scm +++ b/runtime/queries/blade/injections.scm @@ -1,14 +1,108 @@ -((text) @injection.content - (#set! injection.combined) - (#set! injection.language "php")) +; inherits: html +; tree-sitter-comment injection +; if available ((comment) @injection.content (#set! injection.language "comment")) ((php_only) @injection.content (#set! injection.language "php-only")) -((parameter) @injection.content - (#set! injection.include-children) - (#set! injection.language "php-only")) +((parameter) @injection.content + (#set! injection.include-children) ; You may need this, depending on your editor e.g Helix + (#set! injection.language "php-only")) + +; ; Livewire attributes +(attribute + (attribute_name) @_attr + (#any-of? @_attr + "wire:click" + "wire:submit" + "wire:model" + "wire:loading" + "wire:navigate" + "wire:current" + "wire:cloak" + "wire:dirty" + "wire:confirm" + "wire:transition" + "wire:init" + "wire:poll" + "wire:offline" + "wire:ignore" + "wire:replace" + "wire:show" + "wire:stream" + "wire:text" + ) + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "javascript")) + +; ; See #33 +; ; AlpineJS attributes +(attribute + (attribute_name) @_attr + (#match? @_attr "^x-[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "javascript")) + +; ; Apline Events +(attribute + (attribute_name) @_attr + (#match? @_attr "^@[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "javascript")) + +; ; normal HTML element alpine attributes +(element + (_ + (tag_name) @_tag + (#match? @_tag "[^x][^-]") + (attribute + (attribute_name) @_attr + (#match? @_attr "^:[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.combined) + (#set! injection.language "javascript")))) + +; ; ; Blade escaped JS attributes +; ; <x-foo ::bar="baz" /> +(element + (_ + (tag_name) @_tag + (#match? @_tag "^x-[a-z]+") + (attribute + (attribute_name) @_attr + (#match? @_attr "^::[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "javascript")))) + + +; ; ; Blade escaped JS attributes +; ; <htmlTag :class="baz" /> +(element + (_ + (attribute_name) @_attr + (#match? @_attr "^:[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "javascript"))) + + +; Blade PHP attributes +(element + (_ + (tag_name) @_tag + (#match? @_tag "^x-[a-z]+") + (attribute + (attribute_name) @_attr + (#match? @_attr "^:[a-z]+") + (quoted_attribute_value + (attribute_value) @injection.content) + (#set! injection.language "php-only")))) diff --git a/runtime/queries/blade/rainbows.scm b/runtime/queries/blade/rainbows.scm new file mode 100644 index 00000000..1f2129cf --- /dev/null +++ b/runtime/queries/blade/rainbows.scm @@ -0,0 +1 @@ +; inherits: html diff --git a/runtime/queries/blade/textobjects.scm b/runtime/queries/blade/textobjects.scm new file mode 100644 index 00000000..1f2129cf --- /dev/null +++ b/runtime/queries/blade/textobjects.scm @@ -0,0 +1 @@ +; inherits: html |