From 626195472b358aa8887f62b85e49603d3a12c5d6 Mon Sep 17 00:00:00 2001 From: MrSubidubi Date: Mon, 20 Jul 2026 20:16:34 +0200 Subject: [PATCH] Format Tree-sitter queries --- languages/php/brackets.scm | 15 ++- languages/php/debugger.scm | 21 ++--- languages/php/embedding.scm | 61 +++++-------- languages/php/highlights.scm | 134 ++++++++++++++++++++------- languages/php/indents.scm | 4 +- languages/php/injections.scm | 12 ++- languages/php/outline.scm | 57 +++++------- languages/php/runnables.scm | 156 ++++++++++++++------------------ languages/php/tags.scm | 22 +++-- languages/php/textobjects.scm | 56 ++++++------ languages/phpdoc/highlights.scm | 15 ++- 11 files changed, 300 insertions(+), 253 deletions(-) diff --git a/languages/php/brackets.scm b/languages/php/brackets.scm index 988602a..291213f 100644 --- a/languages/php/brackets.scm +++ b/languages/php/brackets.scm @@ -1,4 +1,11 @@ -("{" @open "}" @close) -("(" @open ")" @close) -("[" @open "]" @close) -("\"" @open "\"" @close) +("{" @open + "}" @close) + +("(" @open + ")" @close) + +("[" @open + "]" @close) + +("\"" @open + "\"" @close) diff --git a/languages/php/debugger.scm b/languages/php/debugger.scm index d6520af..80c830f 100644 --- a/languages/php/debugger.scm +++ b/languages/php/debugger.scm @@ -1,28 +1,21 @@ ; e.g. `$age = 25` matches `$age` (expression_statement - (assignment_expression - left: (variable_name) @debug-variable - ) -) + (assignment_expression + left: (variable_name) @debug-variable)) ; e.g. `++$age` matches `$age` (expression_statement - (update_expression - argument: (variable_name) @debug-variable - ) -) + (update_expression + argument: (variable_name) @debug-variable)) ; e.g. `if ($age > 18)` matches `$age` (binary_expression - left: (variable_name) @debug-variable -) + left: (variable_name) @debug-variable) ; e.g. `if (18 < $age)` matches `$age` (binary_expression - right: (variable_name) @debug-variable -) + right: (variable_name) @debug-variable) ; e.g. `__construct(int $age)` matches `$age` (simple_parameter - name: (variable_name) @debug-variable -) + name: (variable_name) @debug-variable) diff --git a/languages/php/embedding.scm b/languages/php/embedding.scm index db27777..359fe7e 100644 --- a/languages/php/embedding.scm +++ b/languages/php/embedding.scm @@ -1,36 +1,25 @@ -( - (comment)* @context - . - [ - (function_definition - "function" @name - name: (_) @name - body: (_ - "{" @keep - "}" @keep) @collapse - ) - - (trait_declaration - "trait" @name - name: (_) @name) - - (method_declaration - "function" @name - name: (_) @name - body: (_ - "{" @keep - "}" @keep) @collapse - ) - - (interface_declaration - "interface" @name - name: (_) @name - ) - - (enum_declaration - "enum" @name - name: (_) @name - ) - - ] @item - ) +((comment)* @context + . + [ + (function_definition + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse) + (trait_declaration + "trait" @name + name: (_) @name) + (method_declaration + "function" @name + name: (_) @name + body: (_ + "{" @keep + "}" @keep) @collapse) + (interface_declaration + "interface" @name + name: (_) @name) + (enum_declaration + "enum" @name + name: (_) @name) + ] @item) diff --git a/languages/php/highlights.scm b/languages/php/highlights.scm index 770be86..4e133d9 100644 --- a/languages/php/highlights.scm +++ b/languages/php/highlights.scm @@ -1,28 +1,38 @@ (php_tag) @tag + (php_end_tag) @tag ; Types - (primitive_type) @type.builtin + (cast_type) @type.builtin -(named_type (name) @type) @type -(named_type (qualified_name) @type) @type -; Named arguments (PHP 8+) +(named_type + (name) @type) @type + +(named_type + (qualified_name) @type) @type +; Named arguments (PHP 8+) (argument name: (name) @variable.parameter) ; Functions +(array_creation_expression + "array" @function.builtin) -(array_creation_expression "array" @function.builtin) -(list_literal "list" @function.builtin) +(list_literal + "list" @function.builtin) (method_declaration name: (name) @function.method) (function_call_expression - function: [(qualified_name (name)) (name)] @function) + function: [ + (qualified_name + (name)) + (name) + ] @function) (scoped_call_expression name: (name) @function) @@ -37,48 +47,52 @@ name: (name) @function) ; Member - (property_element (variable_name) @property) (member_access_expression - name: (variable_name (name)) @property) + name: (variable_name + (name)) @property) + (member_access_expression name: (name) @property) + (nullsafe_member_access_expression - name: (variable_name (name)) @property) + name: (variable_name + (name)) @property) + (nullsafe_member_access_expression name: (name) @property) ; Class constant access (e.g., Class::CONSTANT) - (class_constant_access_expression - (_) (name) @constant) + (_) + (name) @constant) ; Special classes - (relative_scope) @constructor -((object_creation_expression (name) @constructor) - (#any-of? @constructor "self" "parent")) +((object_creation_expression + (name) @constructor) + (#any-of? @constructor "self" "parent")) ((binary_expression operator: "instanceof" right: (name) @constructor) - (#any-of? @constructor "self" "parent")) + (#any-of? @constructor "self" "parent")) ; Variables - ((name) @constructor - (#match? @constructor "^[A-Z]")) + (#match? @constructor "^[A-Z]")) ((name) @constant - (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) + (#match? @constant "^_?[A-Z][A-Z\\d_]+$")) + ((name) @constant.builtin - (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) + (#match? @constant.builtin "^__[A-Z][A-Z\d_]+__$")) ((name) @variable.builtin - (#eq? @variable.builtin "this")) + (#eq? @variable.builtin "this")) (variable_name) @variable @@ -91,14 +105,18 @@ (heredoc_body) (nowdoc_body) ] @string + (boolean) @constant.builtin + (null) @constant.builtin + (integer) @number + (float) @number + (comment) @comment ; Operators - [ "=" "+=" @@ -114,7 +132,6 @@ "^=" "<<=" ">>=" - "+" "-" "*" @@ -122,7 +139,6 @@ "%" "**" "." - "==" "!=" "===" @@ -132,32 +148,25 @@ "<=" ">=" "<=>" - "&&" "||" "!" - "??" "?" ":" - "&" "|" "^" "~" "<<" ">>" - "++" "--" - "@" - "$" ] @operator ; punctuation - [ "(" ")" @@ -168,68 +177,127 @@ ] @punctuation.bracket ; "$" @punctuation.special - ; Keywords - "abstract" @keyword + "and" @keyword + "as" @keyword + "break" @keyword + "case" @keyword + "catch" @keyword + "class" @keyword + "clone" @keyword + "const" @keyword + "continue" @keyword + "declare" @keyword + "default" @keyword + "do" @keyword + "echo" @keyword + "else" @keyword + "elseif" @keyword + "enum" @keyword + "enddeclare" @keyword + "endfor" @keyword + "endforeach" @keyword + "endif" @keyword + "endswitch" @keyword + "endwhile" @keyword + "extends" @keyword + "final" @keyword + "readonly" @keyword + "finally" @keyword + "for" @keyword + "foreach" @keyword + "fn" @keyword + "function" @keyword + "global" @keyword + "goto" @keyword + "if" @keyword + "implements" @keyword + "include_once" @keyword + "include" @keyword + "instanceof" @keyword + "insteadof" @keyword + "interface" @keyword + "match" @keyword + "namespace" @keyword + "new" @keyword + "or" @keyword + "print" @keyword + "private" @keyword + "protected" @keyword + "public" @keyword + "readonly" @keyword + "require_once" @keyword + "require" @keyword + "return" @keyword + "static" @keyword + "switch" @keyword + "throw" @keyword + "trait" @keyword + "try" @keyword + "use" @keyword + "while" @keyword + "xor" @keyword + "yield" @keyword + "yield from" @keyword diff --git a/languages/php/indents.scm b/languages/php/indents.scm index e975469..a768bb0 100644 --- a/languages/php/indents.scm +++ b/languages/php/indents.scm @@ -1 +1,3 @@ -(_ "{" "}" @end) @indent +(_ + "{" + "}" @end) @indent diff --git a/languages/php/injections.scm b/languages/php/injections.scm index c5f63f7..ddaecbd 100644 --- a/languages/php/injections.scm +++ b/languages/php/injections.scm @@ -1,14 +1,16 @@ ((text) @injection.content - (#set! injection.language "html") - (#set! injection.combined)) + (#set! injection.language "html") + (#set! injection.combined)) ((comment) @injection.content (#match? @injection.content "^/\\*\\*[^*]") (#set! injection.language "phpdoc")) ((comment) @injection.content - (#set! injection.language "comment")) + (#set! injection.language "comment")) -((heredoc_body) (heredoc_end) @injection.language) @injection.content +((heredoc_body) + (heredoc_end) @injection.language) @injection.content -((nowdoc_body) (heredoc_end) @injection.language) @injection.content +((nowdoc_body) + (heredoc_end) @injection.language) @injection.content diff --git a/languages/php/outline.scm b/languages/php/outline.scm index 5adc0b8..365e864 100644 --- a/languages/php/outline.scm +++ b/languages/php/outline.scm @@ -1,52 +1,43 @@ (class_declaration - "class" @context - name: (name) @name - ) @item + "class" @context + name: (name) @name) @item (function_definition - "function" @context - name: (_) @name - ) @item + "function" @context + name: (_) @name) @item (method_declaration - "function" @context - name: (_) @name - ) @item + "function" @context + name: (_) @name) @item (interface_declaration - "interface" @context - name: (_) @name - ) @item + "interface" @context + name: (_) @name) @item (enum_declaration - "enum" @context - name: (_) @name - ) @item + "enum" @context + name: (_) @name) @item (trait_declaration - "trait" @context - name: (_) @name - ) @item + "trait" @context + name: (_) @name) @item ; Add support for Pest runnable (function_call_expression - function: (_) @context - (#any-of? @context "it" "test" "describe") - arguments: (arguments - . - (argument - [ - (encapsed_string (string_content) @name) - (string (string_content) @name) - ] - ) - ) -) @item + function: (_) @context + (#any-of? @context "it" "test" "describe") + arguments: (arguments + . + (argument + [ + (encapsed_string + (string_content) @name) + (string + (string_content) @name) + ]))) @item (comment) @annotation (property_declaration (property_element - name: (variable_name) @name - ) -) @item + name: (variable_name) @name)) @item diff --git a/languages/php/runnables.scm b/languages/php/runnables.scm index 183cf88..704bcf3 100644 --- a/languages/php/runnables.scm +++ b/languages/php/runnables.scm @@ -2,108 +2,86 @@ ; and that doesn't have the abstract modifier ; and have a method that follow the naming convention of PHPUnit test methods ; and the method is public -( - (class_declaration - (_)* @_modifier - (#not-any-eq? @_modifier "abstract") - . - name: (_) @_name - (#match? @_name ".*Test$") - body: (declaration_list - (method_declaration - (visibility_modifier)? @_visibility - (#eq? @_visibility "public") - name: (_) @run - (#match? @run "^test.*") - ) - ) - ) @_phpunit-test - (#set! tag phpunit-test) -) +((class_declaration + (_)* @_modifier + (#not-any-eq? @_modifier "abstract") + . + name: (_) @_name + (#match? @_name ".*Test$") + body: (declaration_list + (method_declaration + (visibility_modifier)? @_visibility + (#eq? @_visibility "public") + name: (_) @run + (#match? @run "^test.*")))) @_phpunit-test + (#set! tag phpunit-test)) ; Class that follow the naming convention of PHPUnit test classes ; and that doesn't have the abstract modifier ; and have a method that has the @test annotation ; and the method is public -( - (class_declaration - (_)* @_modifier - (#not-any-eq? @_modifier "abstract") - . - name: (_) @_name - (#match? @_name ".*Test$") - body: (declaration_list - ((comment) @_comment - (#match? @_comment ".*@test\\b.*") - . - (method_declaration - (visibility_modifier)? @_visibility - (#eq? @_visibility "public") - name: (_) @run - (#not-match? @run "^test.*") - )) - ) - ) @_phpunit-test - (#set! tag phpunit-test) -) +((class_declaration + (_)* @_modifier + (#not-any-eq? @_modifier "abstract") + . + name: (_) @_name + (#match? @_name ".*Test$") + body: (declaration_list + ((comment) @_comment + (#match? @_comment ".*@test\\b.*") + . + (method_declaration + (visibility_modifier)? @_visibility + (#eq? @_visibility "public") + name: (_) @run + (#not-match? @run "^test.*"))))) @_phpunit-test + (#set! tag phpunit-test)) ; Class that follow the naming convention of PHPUnit test classes ; and that doesn't have the abstract modifier ; and have a method that has the #[Test] attribute ; and the method is public -( - (class_declaration - (_)* @_modifier - (#not-any-eq? @_modifier "abstract") - . - name: (_) @_name - (#match? @_name ".*Test$") - body: (declaration_list - (method_declaration - (attribute_list - (attribute_group - (attribute (name) @_attribute) - ) - ) - (#eq? @_attribute "Test") - (visibility_modifier)? @_visibility - (#eq? @_visibility "public") - name: (_) @run - (#not-match? @run "^test.*") - ) - ) - ) @_phpunit-test - (#set! tag phpunit-test) -) +((class_declaration + (_)* @_modifier + (#not-any-eq? @_modifier "abstract") + . + name: (_) @_name + (#match? @_name ".*Test$") + body: (declaration_list + (method_declaration + (attribute_list + (attribute_group + (attribute + (name) @_attribute))) + (#eq? @_attribute "Test") + (visibility_modifier)? @_visibility + (#eq? @_visibility "public") + name: (_) @run + (#not-match? @run "^test.*")))) @_phpunit-test + (#set! tag phpunit-test)) ; Class that follow the naming convention of PHPUnit test classes ; and that doesn't have the abstract modifier -( - (class_declaration - (_)* @_modifier - (#not-any-eq? @_modifier "abstract") - . - name: (_) @run - (#match? @run ".*Test$") - ) @_phpunit-test - (#set! tag phpunit-test) -) +((class_declaration + (_)* @_modifier + (#not-any-eq? @_modifier "abstract") + . + name: (_) @run + (#match? @run ".*Test$")) @_phpunit-test + (#set! tag phpunit-test)) ; Add support for Pest runnable ; Function expression that has `it`, `test` or `describe` as the function name -( - (function_call_expression - function: (_) @_name - (#any-of? @_name "it" "test" "describe") - arguments: (arguments - . - (argument - [ - (encapsed_string (string_content) @run) - (string (string_content) @run) - ] - ) - ) - ) @_pest-test - (#set! tag pest-test) -) +((function_call_expression + function: (_) @_name + (#any-of? @_name "it" "test" "describe") + arguments: (arguments + . + (argument + [ + (encapsed_string + (string_content) @run) + (string + (string_content) @run) + ]))) @_pest-test + (#set! tag pest-test)) diff --git a/languages/php/tags.scm b/languages/php/tags.scm index 66d594c..08f9e82 100644 --- a/languages/php/tags.scm +++ b/languages/php/tags.scm @@ -10,10 +10,16 @@ (class_declaration name: (name) @name) @definition.class -(class_interface_clause [(name) (qualified_name)] @name) @impl +(class_interface_clause + [ + (name) + (qualified_name) + ] @name) @impl (property_declaration - (property_element (variable_name (name) @name))) @definition.field + (property_element + (variable_name + (name) @name))) @definition.field (function_definition name: (name) @name) @definition.function @@ -23,14 +29,18 @@ (object_creation_expression [ - (qualified_name (name) @name) - (variable_name (name) @name) + (qualified_name + (name) @name) + (variable_name + (name) @name) ]) @reference.class (function_call_expression function: [ - (qualified_name (name) @name) - (variable_name (name)) @name + (qualified_name + (name) @name) + (variable_name + (name)) @name ]) @reference.call (scoped_call_expression diff --git a/languages/php/textobjects.scm b/languages/php/textobjects.scm index d86a0c1..761c76e 100644 --- a/languages/php/textobjects.scm +++ b/languages/php/textobjects.scm @@ -1,45 +1,45 @@ (function_definition - body: (_ - "{" - (_)* @function.inside - "}" )) @function.around + body: (_ + "{" + (_)* @function.inside + "}")) @function.around (method_declaration - body: (_ - "{" - (_)* @function.inside - "}" )) @function.around + body: (_ + "{" + (_)* @function.inside + "}")) @function.around (method_declaration) @function.around (class_declaration - body: (_ - "{" - (_)* @class.inside - "}")) @class.around + body: (_ + "{" + (_)* @class.inside + "}")) @class.around (interface_declaration - body: (_ - "{" - (_)* @class.inside - "}")) @class.around + body: (_ + "{" + (_)* @class.inside + "}")) @class.around (trait_declaration - body: (_ - "{" - (_)* @class.inside - "}")) @class.around + body: (_ + "{" + (_)* @class.inside + "}")) @class.around (enum_declaration - body: (_ - "{" - (_)* @class.inside - "}")) @class.around + body: (_ + "{" + (_)* @class.inside + "}")) @class.around (namespace_definition - body: (_ - "{" - (_)* @class.inside - "}")) @class.around + body: (_ + "{" + (_)* @class.inside + "}")) @class.around (comment)+ @comment.around diff --git a/languages/phpdoc/highlights.scm b/languages/phpdoc/highlights.scm index 767d8e6..afd24da 100644 --- a/languages/phpdoc/highlights.scm +++ b/languages/phpdoc/highlights.scm @@ -1,7 +1,10 @@ (tag_name) @keyword -(tag (variable_name) @variable) -(variable_name "$" @operator) +(tag + (variable_name) @variable) + +(variable_name + "$" @operator) (tag (tag_name) @keyword @@ -9,5 +12,9 @@ (name) @function.method) (primitive_type) @type.builtin -(named_type (name) @type) @type -(named_type (qualified_name) @type) @type + +(named_type + (name) @type) @type + +(named_type + (qualified_name) @type) @type