diff --git a/queries/apex/textobjects.scm b/queries/apex/textobjects.scm index dfa6e08..2d91056 100644 --- a/queries/apex/textobjects.scm +++ b/queries/apex/textobjects.scm @@ -1,76 +1,105 @@ (class_declaration - body: (class_body) @class.inner) @class.outer + body: (class_body) @class.inner) @class.outer (method_declaration) @function.outer (method_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (constructor_declaration) @function.outer (constructor_declaration - body: (constructor_body . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (constructor_body + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (for_statement - body: (_)? @loop.inner) @loop.outer + body: (_)? @loop.inner) @loop.outer (enhanced_for_statement - body: (_)? @loop.inner) @loop.outer + body: (_)? @loop.inner) @loop.outer (while_statement - body: (_)? @loop.inner) @loop.outer + body: (_)? @loop.inner) @loop.outer (do_statement - body: (_)? @loop.inner) @loop.outer + body: (_)? @loop.inner) @loop.outer (if_statement - condition: (_ (parenthesized_expression) @conditional.inner) @conditional.outer) + condition: (_ + (parenthesized_expression) @conditional.inner) @conditional.outer) (if_statement - consequence: (_)? @conditional.inner - alternative: (_)? @conditional.inner - ) @conditional.outer + consequence: (_)? @conditional.inner + alternative: (_)? @conditional.inner) @conditional.outer (switch_expression - body: (_)? @conditional.inner) @conditional.outer + body: (_)? @conditional.inner) @conditional.outer -;; blocks +; blocks (block) @block.outer - (method_invocation) @call.outer -(method_invocation - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) -;; parameters +(method_invocation + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +; parameters (formal_parameters - "," @parameter.outer._start . - (formal_parameter) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (formal_parameter) @parameter.inner @parameter.outer._end + ) + (formal_parameters - . (formal_parameter) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (formal_parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) (argument_list - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + (argument_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) [ - (line_comment) - (block_comment) + (line_comment) + (block_comment) ] @comment.outer -;; assignment +; assignment (variable_declarator - name: (identifier) @assignment.lhs - value: (_) @assignment.rhs) @assignment.inner @assignment.outer + name: (identifier) @assignment.lhs + value: (_) @assignment.rhs) @assignment.inner @assignment.outer diff --git a/queries/astro/textobjects.scm b/queries/astro/textobjects.scm new file mode 100644 index 0000000..718c4db --- /dev/null +++ b/queries/astro/textobjects.scm @@ -0,0 +1,2 @@ +; inherits: html + diff --git a/queries/bash/textobjects.scm b/queries/bash/textobjects.scm index 2404ce3..dc5bba5 100644 --- a/queries/bash/textobjects.scm +++ b/queries/bash/textobjects.scm @@ -1,27 +1,42 @@ (function_definition) @function.outer (function_definition - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (case_statement) @conditional.outer (if_statement - (_) @conditional.inner ) @conditional.outer + (_) @conditional.inner) @conditional.outer (for_statement - (_) @loop.inner ) @loop.outer + (_) @loop.inner) @loop.outer + (while_statement - (_) @loop.inner ) @loop.outer + (_) @loop.inner) @loop.outer (comment) @comment.outer (regex) @regex.inner ((word) @number.inner - (#match? @number.inner "^[0-9]+$")) + (#match? @number.inner "^[0-9]+$")) (variable_assignment) @assignment.outer -(variable_assignment name: (_) @assignment.inner @assignment.lhs) -(variable_assignment value: (_) @assignment.inner @assignment.rhs) + +(variable_assignment + name: (_) @assignment.inner @assignment.lhs) + +(variable_assignment + value: (_) @assignment.inner @assignment.rhs) + +(command + argument: (word) @parameter.inner) diff --git a/queries/c/textobjects.scm b/queries/c/textobjects.scm index 4c5345e..ec6184c 100644 --- a/queries/c/textobjects.scm +++ b/queries/c/textobjects.scm @@ -1,17 +1,24 @@ -;; TODO: supported by official Tree-sitter if (_)* is more than one node -;; Neovim: will only match if (_) is exactly one node +; TODO: supported by official Tree-sitter if (_)* is more than one node +; Neovim: will only match if (_) is exactly one node ;(function_definition - ;body: (compound_statement - ;("{" (_)* @function.inner "}"))?) @function.outer +;body: (compound_statement +;("{" (_)* @function.inner "}"))?) @function.outer (declaration declarator: (function_declarator)) @function.outer (function_definition - body: (compound_statement)) @function.outer + body: (compound_statement)) @function.outer (function_definition - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (struct_specifier body: (_) @class.inner) @class.outer @@ -19,40 +26,110 @@ (enum_specifier body: (_) @class.inner) @class.outer -; conditional +; conditionals (if_statement - consequence: (_)? @conditional.inner - alternative: (_)? @conditional.inner - ) @conditional.outer + consequence: (compound_statement + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) @conditional.outer (if_statement + alternative: (else_clause + (compound_statement + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + ))) @conditional.outer + +(if_statement) @conditional.outer + +(if_statement + condition: (_) @conditional.inner + (#offset! @conditional.inner 0 1 0 -1)) + +(while_statement + condition: (_) @conditional.inner + (#offset! @conditional.inner 0 1 0 -1)) + +(do_statement + condition: (_) @conditional.inner + (#offset! @conditional.inner 0 1 0 -1)) + +(for_statement condition: (_) @conditional.inner) ; loops -(for_statement - (_)? @loop.inner) @loop.outer +(while_statement) @loop.outer + (while_statement - (_)? @loop.inner) @loop.outer -(do_statement - (_)? @loop.inner) @loop.outer + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer + +(for_statement) @loop.outer +(for_statement + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer + +(do_statement) @loop.outer + +(do_statement + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer (compound_statement) @block.outer + (comment) @comment.outer (call_expression) @call.outer + (call_expression - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) (return_statement (_)? @return.inner) @return.outer ; Statements - ;(expression_statement ;; this is what we actually want to capture in most cases (";" is missing) probably - ;(_) @statement.inner) ;; the other statement like node type is declaration but declaration has a ";" - +;(_) @statement.inner) ;; the other statement like node type is declaration but declaration has a ";" (compound_statement (_) @statement.outer) @@ -69,18 +146,44 @@ (_) @statement.outer) ((parameter_list - "," @parameter.outer._start . (parameter_declaration) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (parameter_declaration) @parameter.inner @parameter.outer._end) + ) + ((parameter_list - . (parameter_declaration) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (parameter_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((argument_list - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((argument_list - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (number_literal) @number.inner +(declaration + declarator: (init_declarator + declarator: (_) @assignment.lhs + value: (_) @assignment.rhs) @assignment.inner) @assignment.outer + +(declaration + type: (primitive_type) + declarator: (_) @assignment.inner) + +(expression_statement + (assignment_expression + left: (_) @assignment.lhs + right: (_) @assignment.rhs) @assignment.inner) @assignment.outer + diff --git a/queries/c_sharp/textobjects.scm b/queries/c_sharp/textobjects.scm index 6a50c08..2b5e123 100644 --- a/queries/c_sharp/textobjects.scm +++ b/queries/c_sharp/textobjects.scm @@ -1,24 +1,66 @@ -(class_declaration - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) @class.outer +(class_declaration + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) @class.outer (struct_declaration - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) @class.outer + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) @class.outer (method_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) @function.outer + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) @function.outer -(constructor_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) @function.outer - -(lambda_expression - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) @function.outer +(method_declaration + body: (arrow_expression_clause + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + )) @function.outer -;; loops +(constructor_declaration + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) @function.outer + +(lambda_expression + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) @function.outer + +; loops (for_statement body: (_) @loop.inner) @loop.outer @@ -31,7 +73,7 @@ (while_statement (block) @loop.inner) @loop.outer -;; conditionals +; conditionals (if_statement consequence: (_)? @conditional.inner alternative: (_)? @conditional.inner) @conditional.outer @@ -39,32 +81,51 @@ (switch_statement body: (switch_body) @conditional.inner) @conditional.outer -;; calls +; calls (invocation_expression) @call.outer -(invocation_expression - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) - -;; blocks -(_ (block) @block.inner) @block.outer -;; parameters +(invocation_expression + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +; blocks +(_ + (block) @block.inner) @block.outer + +; parameters ((parameter_list - "," @parameter.outer._start . (parameter) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (parameter) @parameter.inner @parameter.outer._end) + ) ((parameter_list - . (parameter) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((argument_list - "," @parameter.outer._start . (argument) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (argument) @parameter.inner @parameter.outer._end) + ) ((argument_list - . (argument) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (argument) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) -;; comments +; comments (comment) @comment.outer diff --git a/queries/cmake/textobjects.scm b/queries/cmake/textobjects.scm index d20dba7..4a5b94b 100644 --- a/queries/cmake/textobjects.scm +++ b/queries/cmake/textobjects.scm @@ -1,32 +1,51 @@ (function_def) @function.outer + (function_def - . (function_command) - . (_)? @function.inner._start + . + (function_command) + . + (_)? @function.inner._start (_) @function.inner._end - . (endfunction_command) . + . + (endfunction_command) + . ) (if_condition) @conditional.outer + (if_condition - . (if_command) - . (_)? @conditional.inner._start + . + (if_command) + . + (_)? @conditional.inner._start (_) @conditional.inner._end - . (endif_command) . + . + (endif_command) + . ) (foreach_loop) @loop.outer + (foreach_loop - . (foreach_command) - . (_)? @loop.inner._start + . + (foreach_command) + . + (_)? @loop.inner._start (_) @loop.inner._end - . (endforeach_command) . + . + (endforeach_command) + . ) - (normal_command) @call.outer + (normal_command - "(" . (_) @call.inner._start - (_)? @call.inner._end . ")" + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" ) (line_comment) @comment.outer diff --git a/queries/cpp/textobjects.scm b/queries/cpp/textobjects.scm index abdda50..0a6e915 100644 --- a/queries/cpp/textobjects.scm +++ b/queries/cpp/textobjects.scm @@ -1,4 +1,5 @@ ; inherits: c + (class_specifier body: (_) @class.inner) @class.outer @@ -6,8 +7,18 @@ type: (enum_specifier) default_value: (initializer_list) @class.inner) @class.outer -(for_range_loop - (_)? @loop.inner) @loop.outer +(for_range_loop) @loop.outer + +(for_range_loop + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) (template_declaration (function_definition) @function.outer) @function.outer.start @@ -19,39 +30,69 @@ (class_specifier) @class.outer) @class.outer.start ((lambda_capture_specifier - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((lambda_capture_specifier - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((template_argument_list - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((template_argument_list - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((template_parameter_list - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((template_parameter_list - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((parameter_list - "," @parameter.outer._start . (optional_parameter_declaration) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (optional_parameter_declaration) @parameter.inner @parameter.outer._end) + ) + ((parameter_list - . (optional_parameter_declaration) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (optional_parameter_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((initializer_list - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end @_end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end @_end) + ) + ((initializer_list - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (new_expression (argument_list) @call.inner) @call.outer diff --git a/queries/css/textobjects.scm b/queries/css/textobjects.scm index 051bbeb..d0d105f 100644 --- a/queries/css/textobjects.scm +++ b/queries/css/textobjects.scm @@ -4,3 +4,18 @@ (color_value) ] @number.inner +(declaration + (property_name) @assignment.lhs + . + ":" + . + (_) @assignment.rhs._start + (_)? @assignment.rhs._end + . + ";" + + ) @assignment.outer + +(declaration + (property_name) @assignment.inner) + diff --git a/queries/dart/textobjects.scm b/queries/dart/textobjects.scm index 6b8c93b..358aa58 100644 --- a/queries/dart/textobjects.scm +++ b/queries/dart/textobjects.scm @@ -1,29 +1,43 @@ ; class -(( - (annotation)? @class.outer.start . - (class_definition - body: (class_body) @class.outer._end @class.inner) @class.outer._start - ) - ) -(mixin_declaration (class_body) @class.inner) @class.outer +(((annotation)? @class.outer.start + . + (class_definition + body: (class_body) @class.outer._end @class.inner) @class.outer._start) + ) + +(mixin_declaration + (class_body) @class.inner) @class.outer + (enum_declaration body: (enum_body) @class.inner) @class.outer + (extension_declaration body: (extension_body) @class.inner) @class.outer ; function/method -(( - (annotation)? @function.outer.start . - [(method_signature) (function_signature)] @function.outer._start . - (function_body) @function.outer._end - ) - ) +(((annotation)? @function.outer.start + . + [ + (method_signature) + (function_signature) + ] @function.outer._start + . + (function_body) @function.outer._end) + ) (function_body - (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) -(type_alias (function_type)? @function.inner) @function.outer +(type_alias + (function_type)? @function.inner) @function.outer ; parameter [ @@ -31,42 +45,59 @@ (normal_parameter_type) (type_parameter) ] @parameter.inner -( -"," @parameter.outer._start . [ - (formal_parameter) - (normal_parameter_type) - (type_parameter) - ] @_par @parameter.outer._end - ) -( - [ + +("," @parameter.outer._start + . + [ + (formal_parameter) + (normal_parameter_type) + (type_parameter) + ] @_par @parameter.outer._end + ) + +([ (formal_parameter) (normal_parameter_type) (type_parameter) - ] @_par @parameter.outer._start . "," @parameter.outer._end - ) +] @_par @parameter.outer._start + . + "," @parameter.outer._end + ) -;; TODO: (_)* not supported yet -> for now this works correctly only with simple arguments +; TODO: (_)* not supported yet -> for now this works correctly only with simple arguments ((arguments - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + ((arguments - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ; call -( - (identifier) @call.outer._start . (selector (argument_part) @call.outer._end) - -) - -( - (identifier) . - (selector - (argument_part - (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - ))) -) +((identifier) @call.outer._start + . + (selector + (argument_part) @call.outer._end) + ) + +((identifier) + . + (selector + (argument_part + (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )))) ; block (block) @block.outer @@ -78,8 +109,10 @@ consequence: (_) alternative: (_)? ] @conditional.inner) @conditional.outer + (switch_statement body: (switch_block) @conditional.inner) @conditional.outer + (conditional_expression [ consequence: (_) @@ -89,8 +122,10 @@ ; loop (for_statement body: (block) @loop.inner) @loop.outer + (while_statement body: (block) @loop.inner) @loop.outer + (do_statement body: (block) @loop.inner) @loop.outer diff --git a/queries/ecma/textobjects.scm b/queries/ecma/textobjects.scm index 3fbdcfd..cfa7cfc 100644 --- a/queries/ecma/textobjects.scm +++ b/queries/ecma/textobjects.scm @@ -1,16 +1,30 @@ (function_declaration body: (statement_block)) @function.outer -(function +(function_expression body: (statement_block)) @function.outer (function_declaration - body: (statement_block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) - -(function - body: (statement_block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (statement_block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + +(function_expression + body: (statement_block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (export_statement (function_declaration) @function.outer) @function.outer.start @@ -19,15 +33,29 @@ body: (_) @function.inner) @function.outer (arrow_function - body: (statement_block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (statement_block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (method_definition body: (statement_block)) @function.outer (method_definition - body: (statement_block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (statement_block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (class_declaration body: (class_body) @class.inner) @class.outer @@ -36,87 +64,190 @@ (class_declaration) @class.outer) @class.outer.start (for_in_statement - body: (statement_block . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) @loop.outer + body: (statement_block + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer (for_statement - body: (statement_block . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) @loop.outer + body: (statement_block + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer (while_statement - body: (statement_block . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) @loop.outer + body: (statement_block + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer (do_statement - body: (statement_block . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) @loop.outer + body: (statement_block + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) @loop.outer + +(if_statement + consequence: (statement_block + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) @conditional.outer (if_statement - consequence: (statement_block . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" - )) @conditional.outer + alternative: (else_clause + (statement_block + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + ))) @conditional.outer + +(if_statement) @conditional.outer (switch_statement body: (_)? @conditional.inner) @conditional.outer (call_expression) @call.outer -(call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) - -;; blocks -(_ (statement_block) @block.inner) @block.outer -;; parameters +(call_expression + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +((new_expression + constructor: (identifier) @_cons + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")") @_args) + + ) + +; blocks +(_ + (statement_block) @block.inner) @block.outer + +; parameters ; function ({ x }) ... ; function ([ x ]) ... ; function (v = default_value) (formal_parameters - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end - ) + ) + (formal_parameters - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) ; If the array/object pattern is the first parameter, treat its elements as the argument list (formal_parameters - . (_ - [(object_pattern "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - (array_pattern "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end)] - ) - ) -(formal_parameters - . (_ - [(object_pattern . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - (array_pattern . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end)] - ) - ) - + . + (_ + [ + (object_pattern + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + (array_pattern + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ]) + ) -;; arguments +(formal_parameters + . + (_ + [ + (object_pattern + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + (array_pattern + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ]) + ) + +; arguments (arguments - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end - ) + ) + (arguments - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) -;; comment +; comment (comment) @comment.outer -;; regex -(regex (regex_pattern) @regex.inner) @regex.outer +; regex +(regex + (regex_pattern) @regex.inner) @regex.outer -;; number +; number (number) @number.inner (variable_declarator - name: (_) @assignment.lhs - value: (_) @assignment.inner @assignment.rhs) @assignment.outer + name: (_) @assignment.lhs + value: (_) @assignment.inner @assignment.rhs) @assignment.outer (variable_declarator - name: (_) @assignment.inner) + name: (_) @assignment.inner) + +(object + (pair + key: (_) @assignment.lhs + value: (_) @assignment.inner @assignment.rhs) @assignment.outer) diff --git a/queries/elixir/textobjects.scm b/queries/elixir/textobjects.scm index 4b9dafb..b0636f5 100644 --- a/queries/elixir/textobjects.scm +++ b/queries/elixir/textobjects.scm @@ -1,101 +1,125 @@ ; Block Objects ([ - (do_block "do" . (_) @_do @block.inner._start (_) @block.inner._end . "end") - (do_block "do" . ((_) @_do @block.inner._start) @block.inner._end . "end") -] ) @block.outer + (do_block + "do" + . + (_) @_do @block.inner._start + (_) @block.inner._end + . + "end") + (do_block + "do" + . + ((_) @_do @block.inner._start) @block.inner._end + . + "end") +] + ) @block.outer ; Class Objects (Modules, Protocols) ; multiple children (call - target: ((identifier) @_identifier (#any-of? @_identifier - "defmodule" - "defprotocol" - "defimpl" - )) - (arguments (alias)) - (do_block "do" . (_) @_do @class.inner._start (_) @class.inner._end . "end") - -) @class.outer + target: ((identifier) @_identifier + (#any-of? @_identifier "defmodule" "defprotocol" "defimpl")) + (arguments + (alias)) + (do_block + "do" + . + (_) @_do @class.inner._start + (_) @class.inner._end + . + "end") + ) @class.outer ; single child match (call - target: ((identifier) @_identifier (#any-of? @_identifier - "defmodule" - "defprotocol" - "defimpl" - )) - (arguments (alias)) - (do_block "do" . (_) @class.inner . "end") -) @class.outer + target: ((identifier) @_identifier + (#any-of? @_identifier "defmodule" "defprotocol" "defimpl")) + (arguments + (alias)) + (do_block + "do" + . + (_) @class.inner + . + "end")) @class.outer ; Function, Parameter, and Call Objects (anonymous_function - (stab_clause - right: (body) @function.inner) -) @function.outer + (stab_clause + right: (body) @function.inner)) @function.outer -(call - target: ((identifier) @_identifier (#any-of? @_identifier - "def" - "defmacro" - "defmacrop" - "defn" - "defnp" - "defp" - )) - (arguments (call [ - (arguments (_) @parameter.inner . "," @_delimiter) - (arguments ((_) @parameter.inner) @_delimiter .) - ] )) +(call + target: ((identifier) @_identifier + (#any-of? @_identifier "def" "defmacro" "defmacrop" "defn" "defnp" "defp")) + (arguments + (call + [ + (arguments + (_) @parameter.inner + . + "," @_delimiter) + (arguments + ((_) @parameter.inner) @_delimiter .) + ] + )) [ - (do_block "do" . (_) @_do @function.inner._start (_) @function.inner._end . "end") - (do_block "do" . ((_) @_do @function.inner._start) @function.inner._end . "end") + (do_block + "do" + . + (_) @_do @function.inner._start + (_) @function.inner._end + . + "end") + (do_block + "do" + . + ((_) @_do @function.inner._start) @function.inner._end + . + "end") ] - -) @function.outer + ) @function.outer -(call - target: ((identifier) @_identifier (#any-of? @_identifier - "def" - "defmacro" - "defmacrop" - "defn" - "defnp" - "defp" - )) - (arguments (call [ - (arguments (_) @parameter.inner @parameter.outer._start . "," @_delimiter @parameter.outer._end) - (arguments ((_) @parameter.inner @parameter.outer._start) @_delimiter @parameter.outer._end .) - ] ) +(call + target: ((identifier) @_identifier + (#any-of? @_identifier "def" "defmacro" "defmacrop" "defn" "defnp" "defp")) + (arguments + (call + [ + (arguments + (_) @parameter.inner @parameter.outer._start + . + "," @_delimiter @parameter.outer._end) + (arguments + ((_) @parameter.inner @parameter.outer._start) @_delimiter @parameter.outer._end .) + ] + ) (keywords (pair - value: (_) @function.inner)) - ) -) @function.outer + value: (_) @function.inner)))) @function.outer ; Comment Objects (comment) @comment.outer ; Documentation Objects -(unary_operator +(unary_operator operator: "@" - operand: ( - call target: ((identifier) @_identifier (#any-of? @_identifier - "moduledoc" - "typedoc" - "shortdoc" - "doc" - )) - (arguments [ - ; attributes style documentation - ; @doc deprecated: "...." - (keywords) @comment.inner - ; heredoc style documentation - ; @moduledoc """""" - (string (quoted_content) @comment.inner) - ])) -) @comment.outer + operand: (call + target: ((identifier) @_identifier + (#any-of? @_identifier "moduledoc" "typedoc" "shortdoc" "doc")) + (arguments + [ + ; attributes style documentation + ; @doc deprecated: "...." + (keywords) @comment.inner + ; heredoc style documentation + ; @moduledoc """""" + (string + (quoted_content) @comment.inner) + ]))) @comment.outer ; Regex Objects -(sigil (quoted_content) @regex.inner) @regex.outer +(sigil + (quoted_content) @regex.inner) @regex.outer diff --git a/queries/elm/textobjects.scm b/queries/elm/textobjects.scm index 88990bd..510ad0b 100644 --- a/queries/elm/textobjects.scm +++ b/queries/elm/textobjects.scm @@ -1,32 +1,26 @@ -;; Functions +; Functions ; top level function with type annotation and doc comment -( - (module_declaration) +((module_declaration) (block_comment) @function.outer.start . (type_annotation) . (value_declaration - body: (_)? @function.inner) @function.outer -) + body: (_)? @function.inner) @function.outer) ; top level function with type annotation -( - (module_declaration) +((module_declaration) (type_annotation) @function.outer.start . (value_declaration - body: (_)? @function.inner) @function.outer -) + body: (_)? @function.inner) @function.outer) ; top level function without type annotation -( - (module_declaration) +((module_declaration) (value_declaration - body: (_)? @function.inner) @function.outer -) + body: (_)? @function.inner) @function.outer) -;; Comments +; Comments [ (block_comment) (line_comment) @@ -34,52 +28,52 @@ ; Conditionals (if_else_expr - exprList: (_) - exprList: (_) @conditional.inner) @conditional.outer + exprList: (_) + exprList: (_) @conditional.inner) @conditional.outer (case_of_expr - branch: (case_of_branch) @conditional.inner) @conditional.outer + branch: (case_of_branch) @conditional.inner) @conditional.outer -;; Parameters +; Parameters ; type annotations ((type_expression - (arrow) @parameter.outer._start . - (type_ref) @parameter.inner @parameter.outer._end - ) + (arrow) @parameter.outer._start + . + (type_ref) @parameter.inner @parameter.outer._end) ) ((type_expression - . - (type_ref) @parameter.inner @parameter.outer._start - . (arrow)? @parameter.outer._end - ) + . + (type_ref) @parameter.inner @parameter.outer._start + . + (arrow)? @parameter.outer._end) ) ; list items ((list_expr - "," @parameter.outer._start . - exprList: (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + exprList: (_) @parameter.inner @parameter.outer._end) ) ((list_expr - . - exprList: (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + exprList: (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ; tuple items ((tuple_expr - "," @parameter.outer._start . - expr: (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + expr: (_) @parameter.inner @parameter.outer._end) ) ((tuple_expr - . - expr: (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + expr: (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) diff --git a/queries/fennel/textobjects.scm b/queries/fennel/textobjects.scm index d86a0ce..a23d2af 100644 --- a/queries/fennel/textobjects.scm +++ b/queries/fennel/textobjects.scm @@ -1,53 +1,42 @@ - ; https://fennel-lang.org/reference - (comment) @comment.outer -(_ . "(" ")" .) @statement.outer - -; functions -((fn . name: (_)? . (parameters) . docstring: (_)? . (_) @function.inner._start . (_)* . (_)? @function.inner._end .) - ) @function.outer - -((lambda . name: (_)? . (parameters) . docstring: (_)? . (_) @function.inner._start . (_)* . (_)? @function.inner._end .) - ) @function.outer - -(hashfn ["#" "hashfn"] @function.outer.start (_) @function.inner) @function.outer - -; parameters -(parameters (_) @parameter.inner) -(parameters (_) @parameter.outer) +(_ + . + "(" + ")" .) @statement.outer + +; functions & parameters +(list + . + (symbol) @_fn + (symbol)? @_fn_name + (sequence + (_) @parameter.inner) + (_)* @function.inner + (#any-of? @_fn "fn" "lambda" "λ")) @function.outer ; call -((list . [(multi_symbol) (symbol)] @_sym . (_) @call.inner._start . (_)* . (_)? @call.inner._end .) - - (#not-any-of? @_sym "if" "do" "while" "for" "let" "when")) @call.outer +(list + . + (symbol) @_fn_name + (_)* @call.inner + (#not-any-of? @_fn_name "if" "do" "while" "for" "each" "let" "when" "fn")) @call.outer ; conditionals -((list . ((symbol) @_if (#any-of? @_if "if" "when")) . (_) . - (_) @conditional.inner._start . - (_)* . - (_)? @conditional.inner._end .) - ) @conditional.outer - +(list + (symbol) @_cond + (_) + (_)* @conditional.inner + (#any-of? @_cond "if" "when")) @conditional.outer ; loops -((for . (for_clause) . - (_) @loop.inner._start . - (_)* . - (_)? @loop.inner._end .) - ) @loop.outer - -((each . (_) . - (_) @loop.inner._start . - (_)* . - (_)? @loop.inner._end .) - ) @loop.outer - -((list . ((symbol) @_while (#eq? @_while "while")) . (_) . - (_) @loop.inner._start . - (_)* . - (_)? @loop.inner._end .) - ) @loop.outer - +(list + . + (symbol) @_sym + . + (_) + . + (_)* @loop.inner + (#any-of? @_sym "each" "while" "for")) @loop.outer diff --git a/queries/fish/textobjects.scm b/queries/fish/textobjects.scm index 525ae35..402f21f 100644 --- a/queries/fish/textobjects.scm +++ b/queries/fish/textobjects.scm @@ -1,48 +1,52 @@ -(function_definition) @function.outer +; assignment +(command + name: (word) @_command + argument: (word) @_varname @assignment.lhs @assignment.inner + argument: (_)* @assignment.rhs + (#not-lua-match? @_varname "[-].*") + (#eq? @_command "set")) @assignment.outer (command name: (word) @_name argument: (_)* @assignment.inner (#eq? @_name "set")) -;; block +; block ([ - (case_clause) - (if_statement) - (switch_statement) - (else_clause) - (for_statement) - (while_statement) + (case_clause) + (if_statement) + (switch_statement) + (else_clause) + (for_statement) + (while_statement) ]) @block.outer - - -;; call +; call ; call.inner doesn't work because it can't select *all* arguments (command) @call.outer -;; comment +; comment ; leave space after comment marker if there is one ((comment) @comment.inner @comment.outer - (#offset! @comment.inner 0 2 0) - (#match? @comment.outer "# .*")) + (#offset! @comment.inner 0 2 0) + (#match? @comment.outer "# .*")) ; else remove everything accept comment marker ((comment) @comment.inner @comment.outer (#offset! @comment.inner 0 1 0)) -;; conditional +; conditional (if_statement (command) @conditional.inner) @conditional.outer (switch_statement (_) @conditional.inner) @conditional.outer -;; function +; function ((function_definition) @function.inner @function.outer (#offset! @function.inner 1 0 -1 1)) -;; loop +; loop (for_statement (_) @loop.inner) @loop.outer @@ -50,16 +54,20 @@ condition: (command) (command) @loop.inner) @loop.outer -;; number -[(integer) (float)] @number.inner +; number +[ + (integer) + (float) +] @number.inner -;; parameter +; parameter (command argument: (_) @parameter.outer) -;; return -(return (_) @return.inner) @return.outer +; return +(return + (_) @return.inner) @return.outer -;; statement +; statement (command) @statement.outer diff --git a/queries/foam/textobjects.scm b/queries/foam/textobjects.scm index 3a712e7..885d2c8 100644 --- a/queries/foam/textobjects.scm +++ b/queries/foam/textobjects.scm @@ -1,9 +1,19 @@ (dict) @class.outer -((dict_core) @class.inner) -((key_value value: _? @function.inner._start (_)* _? @parameter.inner @function.inner._end) - ) @function.outer -(code (_)* @class.inner) @class.outer -((comment) @comment.outer._start ((comment)+) @comment.outer._end - ) + +(dict_core) @class.inner + +((key_value + value: _? @function.inner._start + (_)* + _? @parameter.inner @function.inner._end) + ) @function.outer + +(code + (_)* @class.inner) @class.outer + +((comment) @comment.outer._start + (comment)+ @comment.outer._end + ) + (comment) @comment.inner diff --git a/queries/gdscript/textobjects.scm b/queries/gdscript/textobjects.scm new file mode 100644 index 0000000..e5bd113 --- /dev/null +++ b/queries/gdscript/textobjects.scm @@ -0,0 +1,71 @@ +(function_definition + body: (_) @function.inner) @function.outer + +(constructor_definition + body: (_) @function.inner) @function.outer + +(class_definition + body: (_) @class.inner) @class.outer + +(if_statement + body: (_) @conditional.inner) @conditional.outer + +(if_statement + alternative: (_ + (_) @conditional.inner)?) @conditional.outer + +(if_statement + condition: (_) @conditional.inner) + +[ + (for_statement) + (while_statement) +] @loop.outer + +(while_statement + body: (_) @loop.inner) + +(for_statement + body: (_) @loop.inner) + +(comment) @comment.outer + +(parameters + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(parameters + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +(arguments + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(arguments + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +(array + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(array + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + diff --git a/queries/glimmer/textobjects.scm b/queries/glimmer/textobjects.scm index ac925f0..b695d29 100644 --- a/queries/glimmer/textobjects.scm +++ b/queries/glimmer/textobjects.scm @@ -1,29 +1,66 @@ [ - (element_node) - (block_statement) + (element_node) + (block_statement) ] @function.outer - [ - (mustache_statement) - (block_statement_start) - ] @block.outer +[ + (mustache_statement) + (block_statement_start) +] @block.outer (attribute_node) @attribute.outer + (attribute_node [ - (concat_statement) - (mustache_statement) + (concat_statement) + (mustache_statement) ] @attribute.inner) -(element_node (element_node_start) . (_) @function.inner . (element_node_end)) -(block_statement (block_statement_start) . (_) @function.inner . (block_statement_end)) +(element_node + (element_node_start) + . + (_) @function.inner + . + (element_node_end)) + +(block_statement + (block_statement_start) + . + (_) @function.inner + . + (block_statement_end)) + +((element_node + (element_node_start) + . + (_) @function.inner._start + (_) @function.inner._end + . + (element_node_end)) + ) + +((block_statement + (block_statement_start) + . + (_) @function.inner._start + (_) @function.inner._end + . + (block_statement_end)) + ) + +(mustache_statement + . + "{{" + (_) @block.inner + . + "}}") -((element_node (element_node_start) . (_) @function.inner._start (_) @function.inner._end . (element_node_end)) - ) -((block_statement (block_statement_start) . (_) @function.inner._start (_) @function.inner._end . (block_statement_end)) - ) -(mustache_statement . "{{" (_) @block.inner . "}}") -(block_statement_start . "{{#" (_) @block.inner . "}}") +(block_statement_start + . + "{{#" + (_) @block.inner + . + "}}") (comment_statement) @comment.outer diff --git a/queries/go/textobjects.scm b/queries/go/textobjects.scm index bfdf160..ac438c1 100644 --- a/queries/go/textobjects.scm +++ b/queries/go/textobjects.scm @@ -1,44 +1,75 @@ -;; inner function textobject +; inner function textobject (function_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) - -;; inner function literals + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + +; inner function literals (func_literal - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) - -;; method as inner function textobject + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + +; method as inner function textobject (method_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) - -;; outer function textobject + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + +; outer function textobject (function_declaration) @function.outer -;; outer function literals -(func_literal (_)?) @function.outer - -;; method as outer function textobject -(method_declaration body: (block)?) @function.outer +; outer function literals +(func_literal + (_)?) @function.outer +; method as outer function textobject +(method_declaration + body: (block)?) @function.outer -;; struct and interface declaration as class textobject? +; struct and interface declaration as class textobject? (type_declaration - (type_spec (type_identifier) (struct_type (field_declaration_list (_)?) @class.inner))) @class.outer + (type_spec + (type_identifier) + (struct_type + (field_declaration_list + (_)?) @class.inner))) @class.outer (type_declaration - (type_spec (type_identifier) (interface_type) @class.inner)) @class.outer + (type_spec + (type_identifier) + (interface_type) @class.inner)) @class.outer -;; struct literals as class textobject +; struct literals as class textobject (composite_literal (type_identifier)? - (struct_type (_))? - (literal_value (_)) @class.inner) @class.outer + (struct_type + (_))? + (literal_value + (_)) @class.inner) @class.outer -;; conditionals +; conditionals (if_statement - alternative: (_ (_) @conditional.inner)?) @conditional.outer + alternative: (_ + (_) @conditional.inner)?) @conditional.outer (if_statement consequence: (block)? @conditional.inner) @@ -46,74 +77,98 @@ (if_statement condition: (_) @conditional.inner) -;; loops +; loops (for_statement body: (block)? @loop.inner) @loop.outer -;; blocks -(_ (block) @block.inner) @block.outer +; blocks +(_ + (block) @block.inner) @block.outer -;; statements -(block (_) @statement.outer) +; statements +(block + (_) @statement.outer) -;; comments +; comments (comment) @comment.outer -;; calls +; calls (call_expression) @call.outer -(call_expression - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) -;; parameters +(call_expression + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +; parameters (parameter_list - "," @parameter.outer._start . + "," @parameter.outer._start + . (parameter_declaration) @parameter.inner @parameter.outer._end - ) + ) + (parameter_list - . (parameter_declaration) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (parameter_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) (parameter_declaration name: (identifier) type: (_)) @parameter.inner (parameter_declaration - name: (identifier) + name: (identifier) type: (_)) @parameter.inner (parameter_list - "," @parameter.outer._start . + "," @parameter.outer._start + . (variadic_parameter_declaration) @parameter.inner @parameter.outer._end - ) + ) -;; arguments +; arguments (argument_list - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end - ) + ) + (argument_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) -;; assignments +; assignments (short_var_declaration left: (_) @assignment.lhs right: (_) @assignment.rhs @assignment.inner) @assignment.outer + (assignment_statement left: (_) @assignment.lhs right: (_) @assignment.rhs @assignment.inner) @assignment.outer + (var_spec name: (_) @assignment.lhs value: (_) @assignment.rhs @assignment.inner) @assignment.outer + (var_spec name: (_) @assignment.inner type: (_)) @assignment.outer + (const_spec name: (_) @assignment.lhs value: (_) @assignment.rhs @assignment.inner) @assignment.outer + (const_spec name: (_) @assignment.inner type: (_)) @assignment.outer diff --git a/queries/haskell/textobjects.scm b/queries/haskell/textobjects.scm index 85792ce..6cd26a3 100644 --- a/queries/haskell/textobjects.scm +++ b/queries/haskell/textobjects.scm @@ -1,101 +1,100 @@ -( - (exp_apply . (exp_name) . (_) @call.inner._start . (_)* . (_)? @call.inner._end .) - -) @call.outer -(exp_infix -(_) -(variable) -(_) -) @call.outer - -(function rhs: (_) @function.inner) @function.outer -;; also treat function signature as @function.outer +((exp_apply + . + (exp_name) + . + (_) @call.inner._start + . + (_)* + . + (_)? @call.inner._end .) + ) @call.outer + +(exp_infix + (_) + (variable) + (_)) @call.outer + +(function + rhs: (_) @function.inner) @function.outer + +; also treat function signature as @function.outer (signature) @function.outer (class) @class.outer -(class (class_body (where) _ @class.inner)) -(instance (where)? . _ @class.inner) @class.outer + +(class + (class_body + (where) + _ @class.inner)) + +(instance + (where)? + . + _ @class.inner) @class.outer (comment) @comment.outer (exp_cond) @conditional.outer (exp_cond - (_) @conditional.inner - ) + (_) @conditional.inner) -;; e.g. forM [1..10] $ \i -> do... +; e.g. forM [1..10] $ \i -> do... (exp_infix (exp_apply - (exp_name)@_name - (#any-of? @_name "for" "for_" "forM" "forM_") - ) + (exp_name) @_name + (#any-of? @_name "for" "for_" "forM" "forM_")) (operator) @_op (#eq? @_op "$") (exp_lambda (_) - (_) @loop.inner - ) -) @loop.outer -;; e.g. forM [1..10] print + (_) @loop.inner)) @loop.outer + +; e.g. forM [1..10] print (exp_apply - (exp_name)@_name + (exp_name) @_name (#any-of? @_name "for" "for_" "forM" "forM_") (_) - (_) @loop.inner -) @loop.outer + (_) @loop.inner) @loop.outer -;; e.g. func x +; e.g. func x (function (patterns - (_) @parameter.outer - ) -) -;; e.g. func mb@(Just x) + (_) @parameter.outer)) + +; e.g. func mb@(Just x) (function (patterns (pat_parens - (_) @parameter.inner - ) - ) -) + (_) @parameter.inner))) + (function (patterns (pat_as (pat_parens - (_) @parameter.inner - ) - ) - ) -) + (_) @parameter.inner)))) + (signature (context (fun - (type_apply) @parameter.inner - ) - ) -) + (type_apply) @parameter.inner))) + (signature (context (fun - (type_name) @parameter.inner - ) - ) -) + (type_name) @parameter.inner))) + (signature (fun - (type_apply) @parameter.inner - ) -) + (type_apply) @parameter.inner)) + (signature (fun - (type_name) @parameter.inner - ) -) + (type_name) @parameter.inner)) + (signature - (type_apply) @parameter.inner -) + (type_apply) @parameter.inner) + (signature - (type_name) @parameter.inner -) + (type_name) @parameter.inner) diff --git a/queries/hcl/textobjects.scm b/queries/hcl/textobjects.scm index 650b363..b17f7a4 100644 --- a/queries/hcl/textobjects.scm +++ b/queries/hcl/textobjects.scm @@ -1,6 +1,69 @@ -(block (body)? @block.inner ) @block.outer +(attribute + (identifier) @assignment.lhs + (expression) @assignment.inner @assignment.rhs) @assignment.outer -(block (body (_) @statement.outer)) +(attribute + (identifier) @assignment.inner) + +(block + (body)? @block.inner) @block.outer + +(block + (body + (_) @statement.outer)) + +(function_call + (function_arguments) @call.inner) @call.outer (comment) @comment.outer +(conditional + (expression) @conditional.inner) @conditional.outer + +(for_cond + (expression) @conditional.inner) @conditional.outer + +(for_expr + (for_object_expr + (for_intro) @loop.inner + (expression) @loop.inner + (expression) @loop.inner + (for_cond)? @loop.inner)) @loop.outer + +(for_expr + (for_object_expr + (for_intro) @loop.inner)) + +(for_expr + (for_object_expr + (expression) @loop.inner)) + +(for_expr + (for_tuple_expr + (for_intro) @loop.inner + (expression) @loop.inner + (for_cond)? @loop.inner)) @loop.outer + +(for_expr + (for_tuple_expr + (for_intro) @loop.inner)) + +(for_expr + (for_tuple_expr + (expression) @loop.inner)) + +(numeric_lit) @number.inner + +((function_arguments + "," @parameter.outer._start + . + (expression) @parameter.inner @parameter.outer._end) + ) + +((function_arguments + . + (expression) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + diff --git a/queries/heex/textobjects.scm b/queries/heex/textobjects.scm index 9ab1cd9..bd59d84 100644 --- a/queries/heex/textobjects.scm +++ b/queries/heex/textobjects.scm @@ -1,10 +1,22 @@ (tag) @function.outer -(tag (start_tag) . (_) @function.inner . (end_tag)) +(tag + (start_tag) + . + (_) @function.inner + . + (end_tag)) (attribute_value) @attribute.inner + (attribute) @attribute.outer -((tag (start_tag) . (_) @function.inner._start (_) @function.inner._end . (end_tag)) - ) +((tag + (start_tag) + . + (_) @function.inner._start + (_) @function.inner._end + . + (end_tag)) + ) diff --git a/queries/html/textobjects.scm b/queries/html/textobjects.scm index 5b8bcec..5bf1602 100644 --- a/queries/html/textobjects.scm +++ b/queries/html/textobjects.scm @@ -1,28 +1,67 @@ (element) @function.outer -(element (start_tag) . (_) @function.inner . (end_tag)) +(element + (start_tag) + . + (_) @function.inner + . + (end_tag)) (attribute_value) @attribute.inner + (attribute) @attribute.outer -((element (start_tag) . (_) @function.inner._start (_) @function.inner._end . (end_tag)) - ) +((element + (start_tag) + . + (_) @function.inner._start + (_) @function.inner._end + . + (end_tag)) + ) (script_element) @function.outer -(script_element (start_tag) . (_) @function.inner . (end_tag)) + +(script_element + (start_tag) + . + (_) @function.inner + . + (end_tag)) (style_element) @function.outer -(style_element (start_tag) . (_) @function.inner . (end_tag)) -((element (start_tag (tag_name) @_tag)) @class.outer - (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$")) +(style_element + (start_tag) + . + (_) @function.inner + . + (end_tag)) + +((element + (start_tag + (tag_name) @_tag)) @class.outer + (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$")) -((element (start_tag (tag_name) @_tag) . (_) @class.inner . (end_tag)) - (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$")) +((element + (start_tag + (tag_name) @_tag) + . + (_) @class.inner + . + (end_tag)) + (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$")) -((element (start_tag (tag_name) @_tag) . (_) @class.inner._start (_) @class.inner._end . (end_tag)) - (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$") - ) +((element + (start_tag + (tag_name) @_tag) + . + (_) @class.inner._start + (_) @class.inner._end + . + (end_tag)) + (#match? @_tag "^(html|section|h[0-9]|header|title|head|body)$") + ) (comment) @comment.outer diff --git a/queries/java/textobjects.scm b/queries/java/textobjects.scm index baa53c8..42f76ed 100644 --- a/queries/java/textobjects.scm +++ b/queries/java/textobjects.scm @@ -4,14 +4,28 @@ (method_declaration) @function.outer (method_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (constructor_declaration) @function.outer (constructor_declaration - body: (constructor_body . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (constructor_body + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (for_statement body: (_)? @loop.inner) @loop.outer @@ -26,43 +40,58 @@ body: (_)? @loop.inner) @loop.outer (if_statement - condition: (_ (parenthesized_expression) @conditional.inner) @conditional.outer) + condition: (_ + (parenthesized_expression) @conditional.inner) @conditional.outer) (if_statement consequence: (_)? @conditional.inner - alternative: (_)? @conditional.inner - ) @conditional.outer + alternative: (_)? @conditional.inner) @conditional.outer (switch_expression body: (_)? @conditional.inner) @conditional.outer -;; blocks +; blocks (block) @block.outer - (method_invocation) @call.outer -(method_invocation - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) -;; parameters +(method_invocation + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +; parameters (formal_parameters - "," @parameter.outer._start . + "," @parameter.outer._start + . (formal_parameter) @parameter.inner @parameter.outer._end - ) + ) + (formal_parameters - . (formal_parameter) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (formal_parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) (argument_list - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end - ) + ) + (argument_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) [ (line_comment) diff --git a/queries/jsx/textobjects.scm b/queries/jsx/textobjects.scm index 6ceeb42..3f7c07b 100644 --- a/queries/jsx/textobjects.scm +++ b/queries/jsx/textobjects.scm @@ -1,4 +1,6 @@ ; inherits: ecma -((jsx_attribute - (property_identifier) (_) @parameter.inner) @parameter.outer) + +(jsx_attribute + (property_identifier) + (_) @parameter.inner) @parameter.outer diff --git a/queries/julia/textobjects.scm b/queries/julia/textobjects.scm index fca54c4..733cae3 100644 --- a/queries/julia/textobjects.scm +++ b/queries/julia/textobjects.scm @@ -1,126 +1,175 @@ -;; Blocks +; Blocks ((compound_statement - . (_)? @block.inner._start + . + (_)? @block.inner._start (_) @block.inner._end .) -) @block.outer + ) @block.outer ((quote_statement - . (_)? @block.inner._start + . + (_)? @block.inner._start (_) @block.inner._end .) -) @block.outer + ) @block.outer ((let_statement - . (_)? @block.inner._start + . + (_)? @block.inner._start (_) @block.inner._end .) -) @block.outer - -;; Conditionals -((if_statement condition: (_) - . (_)? @conditional.inner._start - . - (_) @conditional.inner._end . - ["end" (elseif_clause) (else_clause)]) -) @conditional.outer -((elseif_clause condition: (_) - . (_)? @conditional.inner._start + ) @block.outer + +; Conditionals +((if_statement + condition: (_) + . + (_)? @conditional.inner._start + . + (_) @conditional.inner._end + . + [ + "end" + (elseif_clause) + (else_clause) + ]) + ) @conditional.outer + +((elseif_clause + condition: (_) + . + (_)? @conditional.inner._start (_) @conditional.inner._end .) -) + ) + ((else_clause - . (_)? @conditional.inner._start + . + (_)? @conditional.inner._start (_) @conditional.inner._end .) -) + ) -;; Loops +; Loops (for_statement - . (_)? @loop.inner._start - (_) @loop.inner._end . - + . + (_)? @loop.inner._start + (_) @loop.inner._end + . + "end") @loop.outer + (while_statement - . (_)? @loop.inner._start - (_) @loop.inner._end . - + . + (_)? @loop.inner._start + (_) @loop.inner._end + . + "end") @loop.outer -;; Type definitions +; Type definitions ((struct_definition name: (_) - . (_)? @class.inner._start - (_) @class.inner._end . - "end" -)) @class.outer + . + (_)? @class.inner._start + (_) @class.inner._end + . + "end") + ) @class.outer ((struct_definition name: (_) (type_parameter_list)* - . (_)? @class.inner._start - (_) @class.inner._end . - "end" -)) @class.outer - - -;; Function definitions + . + (_)? @class.inner._start + (_) @class.inner._end + . + "end") + ) @class.outer + +; Function definitions ((function_definition - name: (_) parameters: (_) - . (_)? @function.inner._start - (_) @function.inner._end . - "end" -)) @function.outer + name: (_) + parameters: (_) + . + (_)? @function.inner._start + (_) @function.inner._end + . + "end") + ) @function.outer (short_function_definition - name: (_) parameters: (_) + name: (_) + parameters: (_) (_) @function.inner) @function.outer -(function_expression - [ (identifier) (parameter_list) ] +(function_expression + [ + (identifier) + (parameter_list) + ] "->" (_) @function.inner) @function.outer ((macro_definition - name: (_) parameters: (_) - . (_)? @function.inner._start - (_) @function.inner._end . - "end" -)) @function.outer - -;; Calls + name: (_) + parameters: (_) + . + (_)? @function.inner._start + (_) @function.inner._end + . + "end") + ) @function.outer + +; Calls (call_expression) @call.outer + (call_expression - (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) -;; Parameters +; Parameters ((vector_expression - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ((argument_list - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end) -) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ((argument_list - (_) @parameter.inner @parameter.outer._start - . "," @parameter.outer._end) -) + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) ((parameter_list - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end) -) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ((parameter_list - (_) @parameter.inner @parameter.outer._start - . [","] @parameter.outer._end) -) + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) ; Comments -[(line_comment) (block_comment)] @comment.outer +[ + (line_comment) + (block_comment) +] @comment.outer ; Regex ((prefixed_string_literal - prefix: (identifier) @_prefix) @regex.inner @regex.outer - (#eq? @_prefix "r") - (#offset! @regex.inner 0 2 0 -1)) + prefix: (identifier) @_prefix) @regex.inner @regex.outer + (#eq? @_prefix "r") + (#offset! @regex.inner 0 2 0 -1)) diff --git a/queries/kotlin/textobjects.scm b/queries/kotlin/textobjects.scm index 34a304a..5330827 100644 --- a/queries/kotlin/textobjects.scm +++ b/queries/kotlin/textobjects.scm @@ -2,21 +2,25 @@ [ (class_body) (enum_class_body) - ] @class.inner -) @class.outer + ] @class.inner) @class.outer [ - (function_declaration (function_body) @function.inner) - (getter (function_body) @function.inner) - (setter (function_body) @function.inner) + (function_declaration + (function_body) @function.inner) + (getter + (function_body) @function.inner) + (setter + (function_body) @function.inner) (primary_constructor) ] @function.outer (primary_constructor) @function.inner [ - (parameter (simple_identifier) @parameter.inner) - (class_parameter (simple_identifier) @parameter.inner) + (parameter + (simple_identifier) @parameter.inner) + (class_parameter + (simple_identifier) @parameter.inner) ] @parameter.outer [ @@ -24,13 +28,17 @@ (multiline_comment) ] @comment.outer -(if_expression (control_structure_body) @conditional.inner) @conditional.outer +(if_expression + (control_structure_body) @conditional.inner) @conditional.outer -(when_expression (when_entry) @conditional.inner) @conditional.outer +(when_expression + (when_entry) @conditional.inner) @conditional.outer [ - (for_statement (control_structure_body) @loop.inner) - (while_statement (control_structure_body) @loop.inner) + (for_statement + (control_structure_body) @loop.inner) + (while_statement + (control_structure_body) @loop.inner) ] @loop.outer [ diff --git a/queries/latex/textobjects.scm b/queries/latex/textobjects.scm index 98535e7..8f09a17 100644 --- a/queries/latex/textobjects.scm +++ b/queries/latex/textobjects.scm @@ -1,22 +1,49 @@ ((generic_environment - . (_) - . (_) @block.inner._start - (_) @block.inner._end . (_) . -) @block.outer -) + . + (_) + . + (_) @block.inner._start + (_) @block.inner._end + . + (_) .) @block.outer + ) ((generic_environment (begin - name: (curly_group_text - (text) @_frame)) - . (_) @frame.inner._start - (_) @frame.inner._end . (_) .) @frame.outer - (#eq? @_frame "frame") - ) + name: (curly_group_text + (text) @_frame)) + . + (_) @frame.inner._start + (_) @frame.inner._end + . + (_) .) @frame.outer + (#eq? @_frame "frame") + ) [ (generic_command) -] @statement.outer + (text_mode) +] @call.outer + +(text_mode + (curly_group + "{" + . + (_) @call.inner._start + (_)? @call.inner._end + . + "}") + ) + +(generic_command + (curly_group + "{" + . + (_) @call.inner._start + (_)? @call.inner._end + . + "}") + ) [ (chapter) diff --git a/queries/lua/textobjects.scm b/queries/lua/textobjects.scm index 8b92c2a..d8ac837 100644 --- a/queries/lua/textobjects.scm +++ b/queries/lua/textobjects.scm @@ -1,8 +1,7 @@ ; block - -(_ (block) @block.inner) @block.outer +(_ + (block) @block.inner) @block.outer ; call - (function_call) @call.outer diff --git a/queries/markdown/textobjects.scm b/queries/markdown/textobjects.scm index 085fb11..043cec3 100644 --- a/queries/markdown/textobjects.scm +++ b/queries/markdown/textobjects.scm @@ -6,7 +6,8 @@ (thematic_break) @class.outer -(fenced_code_block (code_fence_content) @block.inner) @block.outer +(fenced_code_block + (code_fence_content) @block.inner) @block.outer [ (paragraph) diff --git a/queries/matlab/textobjects.scm b/queries/matlab/textobjects.scm index 0c42cd7..7f5570e 100644 --- a/queries/matlab/textobjects.scm +++ b/queries/matlab/textobjects.scm @@ -1,37 +1,60 @@ -(_ (block) @block.inner) @block.outer -(block (_) @statement.outer) -(source_file (_) @statement.outer) +(_ + (block) @block.inner) @block.outer + +(block + (_) @statement.outer) + +(source_file + (_) @statement.outer) (function_call (arguments)? @call.inner) @call.outer -((arguments ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((arguments (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) + +((arguments + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) + +((arguments + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) (command) @call.outer -(command (command_argument) @parameter.inner @parameter.outer) + +(command + (command_argument) @parameter.inner @parameter.outer) + (command - (command_argument) @call.inner._start (command_argument)* @call.inner._end . + (command_argument) @call.inner._start + (command_argument)* @call.inner._end + . ) (if_statement (block) @conditional.inner) @conditional.outer + (if_statement (elseif_clause (block) @conditional.inner)) + (if_statement (else_clause (block) @conditional.inner)) (switch_statement - (case_clause (block) @conditional.inner)) @conditional.outer + (case_clause + (block) @conditional.inner)) @conditional.outer (switch_statement - (otherwise_clause (block) @conditional.inner)) + (otherwise_clause + (block) @conditional.inner)) (for_statement (block) @loop.inner) @loop.outer + (while_statement (block) @loop.inner) @loop.outer @@ -47,65 +70,127 @@ (function_definition (block) @function.inner) @function.outer -(function_output (identifier) @parameter.inner @parameter.outer) +(function_output + (identifier) @parameter.inner @parameter.outer) + +((function_arguments + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) + +((function_arguments + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) -((function_arguments ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((function_arguments (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +((multioutput_variable + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) -((multioutput_variable ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((multioutput_variable (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +((multioutput_variable + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) (try_statement (block) @conditional.inner) @conditional.outer + (catch_clause (identifier) @parameter.inner @parameter.outer) + (catch_clause (block) @conditional.inner) (class_definition) @class.outer (number) @number.inner -(_ (return_statement) @return.inner @return.outer) + +(_ + (return_statement) @return.inner @return.outer) + (comment) @comment.outer -(matrix (row) @parameter.outer) -(cell (row) @parameter.outer) -(row (_) @parameter.inner) +(matrix + (row) @parameter.outer) + +(cell + (row) @parameter.outer) + +(row + (_) @parameter.inner) (assignment left: (_) @assignment.lhs (_) @assignment.rhs) @assignment.outer -((superclasses "&"? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((superclasses (_) @parameter.inner @parameter.outer._start . "&" @parameter.outer._end) - ) +((superclasses + "&"? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) -(enum (identifier) @parameter.inner @parameter.outer) +((superclasses + (_) @parameter.inner @parameter.outer._start + . + "&" @parameter.outer._end) + ) -(property name: (_) @parameter.outer @parameter.inner) +(enum + (identifier) @parameter.inner @parameter.outer) -((enum ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((enum (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +(property + name: (_) @parameter.outer @parameter.inner) -((validation_functions ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((validation_functions (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +((enum + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) -((dimensions ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((dimensions (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +((enum + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) -((attributes ","? @parameter.outer._start . (_) @parameter.inner @parameter.outer._end . ) - ) -((attributes (_) @parameter.inner @parameter.outer._start . "," @parameter.outer._end) - ) +((validation_functions + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) + +((validation_functions + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) + +((dimensions + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) + +((dimensions + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) + +((attributes + ","? @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end .) + ) + +((attributes + (_) @parameter.inner @parameter.outer._start + . + "," @parameter.outer._end) + ) diff --git a/queries/nasm/textobjects.scm b/queries/nasm/textobjects.scm index 4801ff5..f3dd140 100644 --- a/queries/nasm/textobjects.scm +++ b/queries/nasm/textobjects.scm @@ -1,16 +1,19 @@ -;; adapted from https://github.com/naclsn/tree-sitter-nasm/blob/main/queries/textobjects.scm - +; adapted from https://github.com/naclsn/tree-sitter-nasm/blob/main/queries/textobjects.scm (preproc_multiline_macro body: (body) @function.inner) @function.outer + (struc_declaration body: (struc_declaration_body) @class.inner) @class.outer + (struc_instance body: (struc_instance_body) @class.inner) @class.outer (preproc_function_def_parameters (word) @parameter.inner) + (call_syntax_arguments (_) @parameter.inner) + (operand) @parameter.inner (comment) @comment.outer diff --git a/queries/nim/textobjects.scm b/queries/nim/textobjects.scm new file mode 100644 index 0000000..f0c08a6 --- /dev/null +++ b/queries/nim/textobjects.scm @@ -0,0 +1,610 @@ +; ============================================================================== +; @attribute.inner +; @attribute.outer +; ============================================================================== +; @function.inner +; @function.outer +(proc_declaration + body: (statement_list) @function.inner) @function.outer + +(func_declaration + body: (statement_list) @function.inner) @function.outer + +(method_declaration + body: (statement_list) @function.inner) @function.outer + +(iterator_declaration + body: (statement_list) @function.inner) @function.outer + +(converter_declaration + body: (statement_list) @function.inner) @function.outer + +(template_declaration + body: (statement_list) @function.inner) @function.outer + +(macro_declaration + body: (statement_list) @function.inner) @function.outer + +(proc_expression + body: (statement_list) @function.inner) @function.outer + +(func_expression + body: (statement_list) @function.inner) @function.outer + +(iterator_expression + body: (statement_list) @function.inner) @function.outer + +; ============================================================================== +; @class.inner +; @class.outer +; NOTE: seems pointless to handle just object declarations differently +; ============================================================================== +; @conditional.inner +; @conditional.outer +[ + (if) + (when) + (conditional_declaration) + (case) + (variant_declaration) + (elif_branch) + (else_branch) + (of_branch) +] @conditional.outer + +(if + condition: (_) @conditional.inner) + +(if + consequence: (statement_list) @conditional.inner) + +(when + condition: (_) @conditional.inner) + +(when + consequence: (statement_list) @conditional.inner) + +(conditional_declaration + condition: (_) @conditional.inner) + +(conditional_declaration + consequence: (field_declaration_list) @conditional.inner) + +(elif_branch + condition: (_) @conditional.inner) + +(elif_branch + consequence: [ + (statement_list) + (field_declaration_list) + ] @conditional.inner) + +(else_branch + consequence: [ + (statement_list) + (field_declaration_list) + ] @conditional.inner) + +(case + value: (_) @conditional.inner) + +(variant_declaration + (variant_discriminator_declaration) @conditional.inner) + +(of_branch + values: (expression_list) @conditional.inner) + +(of_branch + consequence: [ + (statement_list) + (field_declaration_list) + ] @conditional.inner) + +; ============================================================================== +; @loop.inner +; @loop.outer +[ + (for) + (while) +] @loop.outer + +(for + left: (_) @loop.inner._start + right: (_) @loop.inner._end + ) + +(for + body: (statement_list) @loop.inner) + +(while + condition: (_) @loop.inner) + +(while + body: (statement_list) @loop.inner) + +; ============================================================================== +; @call.inner +; @call.outer +(call + (argument_list) @call.inner) @call.outer + +; NOTE: parenthesis are included in @call.inner +; ============================================================================== +; @block.inner +; @block.outer +(case + ":" + . + (_) @block.inner._start + (_) @block.inner._end + . + ) @block.outer + +(object_declaration + (field_declaration_list) @block.inner) @block.outer + +(tuple_type + . + (field_declaration) @block.inner._start + (field_declaration)? @block.inner._end + . + ) @block.outer + +; BUG: @_end anchor not working correctly in all cases +(enum_declaration + . + (enum_field_declaration) @block.inner._start + (enum_field_declaration)? @block.inner._end + . + ) @block.outer + +; BUG: @_end anchor not working correctly in all cases +; using_section +; const_section +; let_section +; var_section +(_ + . + (variable_declaration) @block.inner._start + (variable_declaration) @block.inner._end + . + ) @block.outer + +; BUG: @_end anchor not working correctly in all cases +(type_section + . + (type_declaration) @block.inner._start + (type_declaration) @block.inner._end + . + ) @block.outer + +; BUG: @_end anchor not working correctly in all cases +; (pragma_statement) +; +; (while) +; (static_statement) +; (defer) +; +; (block) +; (if) +; (when) +; (case) +; (try) +; (for) +; +; (proc_declaration) +; (func_declaration) +; (method_declaration) +; (iterator_declaration) +; (macro_declaration) +; (template_declaration) +; (converter_declaration) +; +; (proc_expression) +; (func_expression) +; (iterator_expression) +; +; (concept_declaration) +; (of_branch) +; (elif_branch) +; (else_branch) +; (except_branch) +; (finally_branch) +; +; (do_block) +; (call) +(_ + (statement_list) @block.inner) @block.outer + +; ============================================================================== +; @parameter.inner +; @parameter.outer +; parameters when declaring +(parameter_declaration_list + [ + "," + ";" + ] @parameter.outer._start + . + (parameter_declaration) @parameter.inner @parameter.outer._end + ) + +(parameter_declaration_list + . + (parameter_declaration) @parameter.inner @parameter.outer._start + . + [ + "," + ";" + ]? @parameter.outer._end + ) + +; generic parameters when declaring +(generic_parameter_list + "," @parameter.outer._start + . + (parameter_declaration) @parameter.inner @parameter.outer._end + ) + +(generic_parameter_list + . + (parameter_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; arguments when calling +(argument_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(argument_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; containers +(array_construction + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(array_construction + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +(tuple_construction + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(tuple_construction + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +(curly_construction + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(curly_construction + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; generic arguments when calling +; subscript operator +; generic types +(bracket_expression + right: (argument_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + +(bracket_expression + right: (argument_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + +; import x,x +; import except x,x +; include x,x +; from import x,x +; bind x,x +; mixin x,x +; case of x,x +; try except x,x +(expression_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(expression_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; pragmas +(pragma_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(pragma_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; variable_declaration +; for +; identifier_declaration `x,y: type = value` +(symbol_declaration_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(symbol_declaration_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; infix_expression +(infix_expression + operator: (_) @parameter.outer._start + right: (_) @parameter.inner @parameter.outer._end + ) + +(infix_expression + left: (_) @parameter.inner @parameter.outer._start + operator: (_) @parameter.outer._end + ) + +; tuple_type inline +(field_declaration_list + [ + "," + ";" + ] @parameter.outer._start + . + (field_declaration) @parameter.inner @parameter.outer._end + ) + +(field_declaration_list + . + (field_declaration) @parameter.inner @parameter.outer._start + . + [ + "," + ";" + ]? @parameter.outer._end + ) + +; enum +(enum_declaration + "," @parameter.outer._start + . + (enum_field_declaration) @parameter.inner @parameter.outer._end + ) + +(enum_declaration + . + (enum_field_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; tuple_deconstruct_declaration +(tuple_deconstruct_declaration + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(tuple_deconstruct_declaration + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; concept parameter list +; concept refinement list +(parameter_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(parameter_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +(refinement_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(refinement_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; dot_generic_call `v.call[:type, type]() +(generic_argument_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end + ) + +(generic_argument_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; ============================================================================== +; @regex.inner +; @regex.outer +; ============================================================================== +; @comment.inner +; @comment.outer +(comment + (comment_content) @comment.inner) @comment.outer + +(block_comment + (comment_content) @comment.inner) @comment.outer + +(documentation_comment + (comment_content) @comment.inner) @comment.outer + +(block_documentation_comment + (comment_content) @comment.inner) @comment.outer + +; ============================================================================== +; @assignment.inner +; @assignment.outer +; @assignment.lhs +; @assignment.rhs +(variable_declaration + (symbol_declaration_list) @_symbols @assignment.lhs._start + type: (type_expression)? @_type @assignment.lhs._end + value: (_) @assignment.rhs @assignment.inner + ) @assignment.outer + +(type_declaration + (type_symbol_declaration) @assignment.lhs + . + "=" + . + (_) @assignment.rhs @assignment.inner) @assignment.outer + +(assignment + left: (_) @assignment.lhs + right: (_) @assignment.rhs @assignment.inner) @assignment.outer + +; default parameter in proc decl +; keyword argument in call +; array construction +(colon_expression + left: (_) @assignment.lhs + right: (_) @assignment.rhs @assignment.inner) @assignment.outer + +; object construction +; tuple construction +; table construction +(equal_expression + left: (_) @assignment.lhs + right: (_) @assignment.rhs @assignment.inner) @assignment.outer + +; object declaration fields +; tuple declaration fields +(field_declaration + (symbol_declaration_list) @_symbols @assignment.lhs._start + type: (type_expression)? @_type @assignment.lhs._end + value: (_)? @assignment.rhs @assignment.inner + ) @assignment.outer + +; enum types +(enum_field_declaration + (symbol_declaration) @assignment.lhs + "="? + value: (_)? @assignment.rhs @assignment.inner) @assignment.outer + +; ============================================================================== +; @return.inner +; @return.outer +(return_statement + (_) @return.inner) @return.outer + +; ============================================================================== +; @statement.outer +[ + ; simple + (import_statement) + (import_from_statement) + (export_statement) + (include_statement) + (discard_statement) + (return_statement) + (raise_statement) + (yield_statement) + (break_statement) + (continue_statement) + (assembly_statement) + (bind_statement) + (mixin_statement) + (pragma_statement) + ; complex + (while) + (static_statement) + (defer) + ; declarations + (proc_declaration) + (func_declaration) + (method_declaration) + (iterator_declaration) + (macro_declaration) + (template_declaration) + (converter_declaration) + (using_section) + (const_section) + (let_section) + (var_section) + (type_section) + ; expression statements + (block) + (if) + (when) + (case) + (try) + (for) + (assignment) + ; NOTE: not including + ; simple_expression, call, infix_expression, prefix_expression + ; because it would confusing +] @statement.outer + +; ============================================================================== +; @scopename.inner +; ============================================================================== +; @number.inner +[ + (integer_literal) + (float_literal) +] @number.inner + diff --git a/queries/nix/textobjects.scm b/queries/nix/textobjects.scm index c6f0a2a..1aea890 100644 --- a/queries/nix/textobjects.scm +++ b/queries/nix/textobjects.scm @@ -1,30 +1,24 @@ -;; named function +; named function (binding - (function_expression - ) -) @function.outer + (function_expression)) @function.outer -;; anonymous function +; anonymous function (function_expression - (_) ;; argument - (_) @function.inner -) @function.outer + (_) ; argument + (_) @function.inner) @function.outer (function_expression (formals - (formal) @parameter.inner - ) -) + (formal) @parameter.inner)) + (function_expression (_) @parameter.outer - (_) -) + (_)) (comment) @comment.outer (if_expression - (_) @conditional.inner -) @conditional.outer + (_) @conditional.inner) @conditional.outer [ (integer_expression) diff --git a/queries/odin/textobjects.scm b/queries/odin/textobjects.scm new file mode 100644 index 0000000..16d96f8 --- /dev/null +++ b/queries/odin/textobjects.scm @@ -0,0 +1,142 @@ +; procedures +(procedure_declaration + (_ + (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + ))) @function.outer + +; returns +(return_statement + (_)? @return.inner) @return.outer + +; call function in module +(member_expression + (call_expression)) @call.outer + +; plain call +((_ + (call_expression) @call.outer) @_parent + (#not-has-type? @_parent "member_expression")) + +; call arguments +((call_expression + function: (_) + . + argument: (_) @_first @call.inner._start + argument: (_) @_last @call.inner._end .) + ) + +; block +(block + . + "{" + . + (_) @block.inner._start @block.inner._end + (_)? @block.inner._end + . + "}" + ) @block.outer + +; classes +(struct_declaration + . + (identifier) + . + (tag)* + . + "{" + . + (_) @_first @class.inner._start @_last @class.inner._end + (_)? + "," @_last @class.inner._end + . + "}" + ) @class.outer + +(union_declaration + . + (identifier) + . + (tag)* + . + "{" + . + (_) @_first @class.inner._start @_last @class.inner._end + (_)? + "," @_last @class.inner._end + . + "}" + ) @class.outer + +(enum_declaration + . + (identifier) + . + (tag)* + . + "{" + . + (_) @_first @class.inner._start @_last @class.inner._end + (_)? + "," @_last @class.inner._end + . + "}" + ) @class.outer + +; comments +(comment) @comment.outer + +(block_comment) @comment.outer + +; assignment +; works also for multiple targets in lhs. ex. 'res, ok := get_res()' +((assignment_statement + . + (_) @_first @assignment.lhs._start + (_) @_prelast @assignment.lhs._end + . + (_) @assignment.rhs @assignment.inner .) + ) @assignment.outer + +; attribute +(attribute + (_) @attribute.inner) @attribute.outer + +; number +(number) @number.inner + +; parameters +((parameters + "," @parameter.outer._start + . + (parameter) @parameter.inner @parameter.outer._end) + ) + +((parameters + . + (parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + +((call_expression + function: (_) + "," @parameter.outer._start + . + argument: (_) @parameter.inner @parameter.outer._end) + ) + +((call_expression + function: (_) + . + argument: (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + diff --git a/queries/php/textobjects.scm b/queries/php/textobjects.scm index bed8530..950dcb0 100644 --- a/queries/php/textobjects.scm +++ b/queries/php/textobjects.scm @@ -1,112 +1,237 @@ -;; functions +; functions (function_definition - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + (function_definition) @function.outer (anonymous_function_creation_expression - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + (anonymous_function_creation_expression) @function.outer -;; methods +; methods (method_declaration - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) + (method_declaration) @function.outer -;; traits +; traits (trait_declaration - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) + (trait_declaration) @class.outer -;; interfaces +; interfaces (interface_declaration - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) + (interface_declaration) @class.outer -;; enums +; enums (enum_declaration - body: (enum_declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (enum_declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) + (enum_declaration) @class.outer -;; classes +; classes (class_declaration - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) + (class_declaration) @class.outer -;; loops +; loops (for_statement - (compound_statement . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) + (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) + (for_statement) @loop.outer (foreach_statement - body: (compound_statement . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) + (foreach_statement) @loop.outer (while_statement - body: (compound_statement . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) + (while_statement) @loop.outer (do_statement - body: (compound_statement . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" + )) + (do_statement) @loop.outer -;; conditionals +; conditionals (switch_statement - body: (switch_block . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" - )) + body: (switch_block + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) + (switch_statement) @conditional.outer (if_statement - body: (compound_statement . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) + (if_statement) @conditional.outer (else_clause - body: (compound_statement . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" - ) -) + body: (compound_statement + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) (else_if_clause - body: (compound_statement . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" - ) -) + body: (compound_statement + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" + )) -;; blocks -(_ (switch_block) @block.inner) @block.outer +; blocks +(_ + (switch_block) @block.inner) @block.outer -;; parameters +; parameters (arguments - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end ) + (arguments - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end ) (formal_parameters - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end ) + (formal_parameters - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end ) -;; comments +; comments (comment) @comment.outer -;; call +; call (function_call_expression) @call.outer (member_call_expression) @call.outer @@ -116,22 +241,50 @@ (scoped_call_expression) @call.outer (function_call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) (member_call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) (nullsafe_member_call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) (scoped_call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) -;; statement +; statement [ (expression_statement) (declare_statement) diff --git a/queries/php_only/textobjects.scm b/queries/php_only/textobjects.scm new file mode 100644 index 0000000..7730a8f --- /dev/null +++ b/queries/php_only/textobjects.scm @@ -0,0 +1,2 @@ +; inherits php + diff --git a/queries/python/textobjects.scm b/queries/python/textobjects.scm index 341720b..cc1ee10 100644 --- a/queries/python/textobjects.scm +++ b/queries/python/textobjects.scm @@ -17,7 +17,8 @@ body: (block)? @loop.inner) @loop.outer (if_statement - alternative: (_ (_) @conditional.inner)?) @conditional.outer + alternative: (_ + (_) @conditional.inner)?) @conditional.outer (if_statement consequence: (block)? @conditional.inner) @@ -25,173 +26,192 @@ (if_statement condition: (_) @conditional.inner) -(_ (block) @block.inner) @block.outer +(_ + (block) @block.inner) @block.outer ; leave space after comment marker if there is one ((comment) @comment.inner @comment.outer - (#offset! @comment.inner 0 2 0) - (#match? @comment.outer "# .*")) + (#offset! @comment.inner 0 2 0) + (#match? @comment.outer "# .*")) ; else remove everything accept comment marker ((comment) @comment.inner @comment.outer (#offset! @comment.inner 0 1 0)) +(block + (_) @statement.outer) -(block (_) @statement.outer) -(module (_) @statement.outer) +(module + (_) @statement.outer) (call) @call.outer + (call - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) (return_statement (_)? @return.inner) @return.outer -;; Parameters - +; Parameters ((parameters - "," @parameter.outer._start . - [ - (identifier) - (tuple) - (typed_parameter) - (default_parameter) - (typed_default_parameter) - (dictionary_splat_pattern) - (list_splat_pattern) - ] @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + [ + (identifier) + (tuple) + (typed_parameter) + (default_parameter) + (typed_default_parameter) + (dictionary_splat_pattern) + (list_splat_pattern) + ] @parameter.inner @parameter.outer._end) ) ((parameters - . [ - (identifier) - (tuple) - (typed_parameter) - (default_parameter) - (typed_default_parameter) - (dictionary_splat_pattern) - (list_splat_pattern) - ] @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) - -) + . + [ + (identifier) + (tuple) + (typed_parameter) + (default_parameter) + (typed_default_parameter) + (dictionary_splat_pattern) + (list_splat_pattern) + ] @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((lambda_parameters - "," @parameter.outer._start . - [ - (identifier) - (tuple) - (typed_parameter) - (default_parameter) - (typed_default_parameter) - (dictionary_splat_pattern) - (list_splat_pattern) - ] @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + [ + (identifier) + (tuple) + (typed_parameter) + (default_parameter) + (typed_default_parameter) + (dictionary_splat_pattern) + (list_splat_pattern) + ] @parameter.inner @parameter.outer._end) ) ((lambda_parameters - . [ - (identifier) - (tuple) - (typed_parameter) - (default_parameter) - (typed_default_parameter) - (dictionary_splat_pattern) - (list_splat_pattern) - ] @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + [ + (identifier) + (tuple) + (typed_parameter) + (default_parameter) + (typed_default_parameter) + (dictionary_splat_pattern) + (list_splat_pattern) + ] @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((tuple - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) - -) ((tuple - "(" . - (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end + "(" + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) - -) ((list - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) - -) ((list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((dictionary - . (pair) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (pair) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((dictionary - "," @parameter.outer._start . - (pair) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (pair) @parameter.inner @parameter.outer._end) ) ((argument_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((argument_list - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) ((subscript - "[" . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + "[" + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((subscript - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) ((import_statement - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + ((import_statement - "," @parameter.outer._start - . (_) @parameter.inner @parameter.outer._end - ) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ((import_from_statement - "," @parameter.outer._start - . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) ((import_from_statement - "import" - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end) - ) + "import" + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) [ (integer) @@ -199,11 +219,11 @@ ] @number.inner (assignment - left: (_) @assignment.lhs - right: (_) @assignment.inner @assignment.rhs) @assignment.outer + left: (_) @assignment.lhs + right: (_) @assignment.inner @assignment.rhs) @assignment.outer (assignment - left: (_) @assignment.inner) + left: (_) @assignment.inner) ; TODO: exclude comments using the future negate syntax from tree-sitter diff --git a/queries/ql/textobjects.scm b/queries/ql/textobjects.scm index 49d13f6..19ce9e0 100644 --- a/queries/ql/textobjects.scm +++ b/queries/ql/textobjects.scm @@ -1,14 +1,29 @@ -;; class textobject -(dataclass (typeExpr) (_) @class.inner) @class.outer - -;; function textobject -(charpred (className) (_) @function.inner) @function.outer -(memberPredicate (body) @function.inner) @function.outer -(classlessPredicate (body) @function.inner) @function.outer - -;; scope name textobject -(dataclass name: (className) @scopename.inner) -(classlessPredicate name: (predicateName) @scopename.inner) -(memberPredicate name: (predicateName) @scopename.inner) -(charpred (className) @scopename.inner) +; class textobject +(dataclass + (typeExpr) + (_) @class.inner) @class.outer + +; function textobject +(charpred + (className) + (_) @function.inner) @function.outer + +(memberPredicate + (body) @function.inner) @function.outer + +(classlessPredicate + (body) @function.inner) @function.outer + +; scope name textobject +(dataclass + name: (className) @scopename.inner) + +(classlessPredicate + name: (predicateName) @scopename.inner) + +(memberPredicate + name: (predicateName) @scopename.inner) + +(charpred + (className) @scopename.inner) diff --git a/queries/query/textobjects.scm b/queries/query/textobjects.scm index 28dee09..d7005c9 100644 --- a/queries/query/textobjects.scm +++ b/queries/query/textobjects.scm @@ -6,7 +6,13 @@ (list) ] @block.outer -(program [(named_node) (grouping) (list)] @statement.outer) +(program + [ + (named_node) + (grouping) + (list) + ] @statement.outer) -(parameters (_) @parameter.inner) +(parameters + (_) @parameter.inner) diff --git a/queries/r/textobjects.scm b/queries/r/textobjects.scm index 8b01998..d2f29d1 100644 --- a/queries/r/textobjects.scm +++ b/queries/r/textobjects.scm @@ -1,22 +1,18 @@ ; block - ; call +(call) @call.outer -(call) @call.outer (arguments) @call.inner +(arguments) @call.inner ; class - ; comment - (comment) @comment.outer ; conditional - (if condition: (_)? @conditional.inner) @conditional.outer ; function - [ (function_definition) (lambda_function) @@ -34,52 +30,56 @@ (call) (binary) (brace_list) - ] @function.inner -) @function.outer + ] @function.inner) @function.outer ; loop - [ (while) (repeat) (for) ] @loop.outer -(while body: (_) @loop.inner) +(while + body: (_) @loop.inner) -(repeat body: (_) @loop.inner) +(repeat + body: (_) @loop.inner) -(for body: (_) @loop.inner) +(for + body: (_) @loop.inner) ; statement -(brace_list (_) @statement.outer) -(program (_) @statement.outer) +(brace_list + (_) @statement.outer) +(program + (_) @statement.outer) ; parameter - ((formal_parameters - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) ((formal_parameters - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ((arguments - "," @parameter.outer._start . - (_) @parameter.inner @parameter.outer._end - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) ) ((arguments - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) ) ; number diff --git a/queries/readline/textobjects.scm b/queries/readline/textobjects.scm new file mode 100644 index 0000000..aa099a1 --- /dev/null +++ b/queries/readline/textobjects.scm @@ -0,0 +1,20 @@ +(variable_setting) @statement.outer + +(comment) @comment.outer + +((comment) @comment.inner + (#offset! @comment.inner 0 1 0 0)) + +[ + (alternative) + (consequence) + (test) +] @conditional.inner + +(conditional_construct) @conditional.outer + +[ + (number_value) + (version_number) +] @number.inner + diff --git a/queries/rst/textobjects.scm b/queries/rst/textobjects.scm index a60aaa9..767db8e 100644 --- a/queries/rst/textobjects.scm +++ b/queries/rst/textobjects.scm @@ -1,7 +1,8 @@ (directive body: (body) @function.inner) @function.outer -(section (title) @class.inner) @class.outer +(section + (title) @class.inner) @class.outer (transition) @class.outer @@ -10,7 +11,6 @@ (enumerated_list) (definition_list) (field_list) - (literal_block) (line_block) (block_quote) diff --git a/queries/ruby/textobjects.scm b/queries/ruby/textobjects.scm index 0c479e3..0021248 100644 --- a/queries/ruby/textobjects.scm +++ b/queries/ruby/textobjects.scm @@ -1,35 +1,53 @@ ; @functions (method body: (body_statement) @function.inner) + (method) @function.outer + (singleton_method body: (body_statement) @function.inner) + (singleton_method) @function.outer ; @blocks (block body: (block_body) @block.inner) + (block) @block.outer + (do_block body: (body_statement) @block.inner) + (do_block) @block.outer ; @classes (class body: (body_statement) @class.inner) + (class) @class.outer + (module body: (body_statement) @class.inner) + (module) @class.outer + (singleton_class body: (body_statement) @class.inner) + (singleton_class) @class.outer ; @parameters -(block_parameters (_) @parameter.inner) -(method_parameters (_) @parameter.inner) -(lambda_parameters (_) @parameter.inner) -(argument_list (_) @parameter.inner) +(block_parameters + (_) @parameter.inner) + +(method_parameters + (_) @parameter.inner) + +(lambda_parameters + (_) @parameter.inner) + +(argument_list + (_) @parameter.inner) [ (block_parameters) @@ -42,5 +60,6 @@ (comment) @comment.outer ; @regex -(regex (string_content) @regex.inner) @regex.outer +(regex + (string_content) @regex.inner) @regex.outer diff --git a/queries/rust/textobjects.scm b/queries/rust/textobjects.scm index 7ec5f7d..db50b87 100644 --- a/queries/rust/textobjects.scm +++ b/queries/rust/textobjects.scm @@ -1,48 +1,115 @@ -;; functions +; functions (function_signature_item) @function.outer + (function_item) @function.outer + (function_item - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) -;; quantifies as class(es) +; quantifies as class(es) (struct_item) @class.outer + (struct_item - body: (field_declaration_list . "{" . (_) @class.inner._start [(_)","]? @class.inner._end . "}" - )) + body: (field_declaration_list + . + "{" + . + (_) @class.inner._start + [ + (_) + "," + ]? @class.inner._end + . + "}" + )) (enum_item) @class.outer + (enum_item - body: (enum_variant_list . "{" . (_) @class.inner._start [(_)","]? @class.inner._end . "}" - )) + body: (enum_variant_list + . + "{" + . + (_) @class.inner._start + [ + (_) + "," + ]? @class.inner._end + . + "}" + )) (union_item) @class.outer + (union_item - body: (field_declaration_list . "{" . (_) @class.inner._start [(_)","]? @class.inner._end . "}" - )) + body: (field_declaration_list + . + "{" + . + (_) @class.inner._start + [ + (_) + "," + ]? @class.inner._end + . + "}" + )) (trait_item) @class.outer + (trait_item - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) (impl_item) @class.outer + (impl_item - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) (mod_item) @class.outer + (mod_item - body: (declaration_list . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + body: (declaration_list + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) -;; conditionals +; conditionals (if_expression - alternative: (_ (_) @conditional.inner)? - ) @conditional.outer + alternative: (_ + (_) @conditional.inner)?) @conditional.outer (if_expression - alternative: (else_clause (block) @conditional.inner)) + alternative: (else_clause + (block) @conditional.inner)) (if_expression condition: (_) @conditional.inner) @@ -55,149 +122,296 @@ (match_expression) @conditional.outer -;; loops +; loops (loop_expression - (_)? @loop.inner) @loop.outer + body: (block + . + "{" + . + (_) @loop.inner._start + [ + (_) + "," + ]? @loop.inner._end + . + "}" + )) @loop.outer (while_expression - (_)? @loop.inner) @loop.outer + body: (block + . + "{" + . + (_) @loop.inner._start + [ + (_) + "," + ]? @loop.inner._end + . + "}" + )) @loop.outer (for_expression - body: (block)? @loop.inner) @loop.outer - -;; blocks -(_ (block) @block.inner) @block.outer -(unsafe_block (_)? @block.inner) @block.outer + body: (block + . + "{" + . + (_) @loop.inner._start + [ + (_) + "," + ]? @loop.inner._end + . + "}" + )) @loop.outer + +; blocks +(_ + (block) @block.inner) @block.outer + +(unsafe_block + (_)? @block.inner) @block.outer + +; calls +(macro_invocation) @call.outer + +(macro_invocation + (token_tree + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) -;; calls (call_expression) @call.outer + (call_expression - arguments: (arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + arguments: (arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) -;; returns +; returns (return_expression (_)? @return.inner) @return.outer -;; statements -(block (_) @statement.outer) +; statements +(block + (_) @statement.outer) -;; comments +; comments (line_comment) @comment.outer + (block_comment) @comment.outer -;; parameter +; parameter +((parameters + "," @parameter.outer._start + . + (self_parameter) @parameter.inner @parameter.outer._end) + ) + +((parameters + . + (self_parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((parameters - "," @parameter.outer._start . (parameter) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (parameter) @parameter.inner @parameter.outer._end) + ) + ((parameters - . (parameter) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((parameters - "," @parameter.outer._start . (type_identifier) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (type_identifier) @parameter.inner @parameter.outer._end) + ) + ((parameters - . (type_identifier) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (type_identifier) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((type_parameters - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((type_parameters - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((tuple_pattern - "," @parameter.outer._start . (identifier) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (identifier) @parameter.inner @parameter.outer._end) + ) + ((tuple_pattern - . (identifier) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (identifier) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((tuple_struct_pattern - "," @parameter.outer._start . (identifier) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (identifier) @parameter.inner @parameter.outer._end) + ) + ((tuple_struct_pattern - . (identifier) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (identifier) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (tuple_expression "," @parameter.outer._start - . (_) @parameter.inner @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._end + ) (tuple_expression - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) ((tuple_type - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((tuple_type - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (struct_item body: (field_declaration_list "," @parameter.outer._start - . (_) @parameter.inner @parameter.outer._end - )) + . + (_) @parameter.inner @parameter.outer._end + )) (struct_item body: (field_declaration_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - )) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + )) (struct_expression body: (field_initializer_list "," @parameter.outer._start - . (_) @parameter.inner @parameter.outer._end - )) + . + (_) @parameter.inner @parameter.outer._end + )) (struct_expression body: (field_initializer_list - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - )) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + )) ((closure_parameters - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((closure_parameters - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((arguments - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((arguments - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) ((type_arguments - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((type_arguments - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + +((token_tree + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) -;; Disabled as not available in upstream language grammar repo (will need rust lang update) -;; ((token_tree -;; "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) -;; ) -;; ((token_tree -;; . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) -;; ) +((token_tree + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (scoped_use_list - list: (use_list "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end + list: (use_list + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end )) + (scoped_use_list - list: (use_list . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end + list: (use_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end )) [ @@ -206,16 +420,16 @@ ] @number.inner (let_declaration - pattern: (_) @assignment.lhs - value: (_) @assignment.inner @assignment.rhs) @assignment.outer + pattern: (_) @assignment.lhs + value: (_) @assignment.inner @assignment.rhs) @assignment.outer (let_declaration - pattern: (_) @assignment.inner) + pattern: (_) @assignment.inner) (assignment_expression - left: (_) @assignment.lhs - right: (_) @assignment.inner @assignment.rhs) @assignment.outer + left: (_) @assignment.lhs + right: (_) @assignment.inner @assignment.rhs) @assignment.outer (assignment_expression - left: (_) @assignment.inner) + left: (_) @assignment.inner) diff --git a/queries/scala/textobjects.scm b/queries/scala/textobjects.scm index 7113d15..e4dc37d 100644 --- a/queries/scala/textobjects.scm +++ b/queries/scala/textobjects.scm @@ -5,7 +5,12 @@ body: (template_body)? @class.inner) @class.outer (function_definition - body: [(indented_block) (expression) (indented_cases) (block)] @function.inner) @function.outer + body: [ + (indented_block) + (expression) + (indented_cases) + (block) + ] @function.inner) @function.outer (parameter name: (identifier) @parameter.inner) @parameter.outer diff --git a/queries/slang/textobjects.scm b/queries/slang/textobjects.scm new file mode 100644 index 0000000..882f511 --- /dev/null +++ b/queries/slang/textobjects.scm @@ -0,0 +1,14 @@ +; inherits: hlsl + +(template_declaration + (interface_specifier)) @class.outer.start + +(template_declaration + (extension_specifier)) @class.outer.start + +(extension_specifier + body: (_) @class.inner) @class.outer + +(interface_specifier + body: (_) @class.inner) @class.outer + diff --git a/queries/supercollider/textobjects.scm b/queries/supercollider/textobjects.scm index c5ee0f8..90e148b 100644 --- a/queries/supercollider/textobjects.scm +++ b/queries/supercollider/textobjects.scm @@ -1,52 +1,63 @@ ; conditional (if -true:(function_block)? @conditional.inner -false:(function_block)? @conditional.inner -) @conditional.outer + true: (function_block)? @conditional.inner + false: (function_block)? @conditional.inner) @conditional.outer (if -(_)? @conditional.inner -) @conditional.outer + (_)? @conditional.inner) @conditional.outer ; loops (for -(function_block)? @loop.inner) @loop.outer -(while -(function_block)? @loop.inner) @loop.outer - + (function_block)? @loop.inner) @loop.outer +(while + (function_block)? @loop.inner) @loop.outer (code_block -(_) @block.inner -) @block.outer + (_) @block.inner) @block.outer -(class -) @class.outer +(class) @class.outer (parameter_call_list -(_)? -) @class.inner + (_)?) @class.inner (line_comment) @comment.outer + (block_comment) @comment.outer (function_block -(_) @function.inner -) @function.outer + (_) @function.inner) @function.outer ;parameters ((parameter_call_list -"," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) -) -((parameter_call_list -. (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) -) - + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) -(((symbol)?(identifier) -"," @parameter.outer._start . ((method_name)(function_call(_))) @parameter.inner @parameter.outer._end) -) -(((symbol)?(identifier) -. ((method_name)(function_call(_))) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) -) +((parameter_call_list + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + +(((symbol)? + (identifier) + "," @parameter.outer._start + . + ((method_name) + (function_call + (_))) @parameter.inner @parameter.outer._end) + ) + +(((symbol)? + (identifier) + . + ((method_name) + (function_call + (_))) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) diff --git a/queries/swift/textobjects.scm b/queries/swift/textobjects.scm index dd29abc..ef81090 100644 --- a/queries/swift/textobjects.scm +++ b/queries/swift/textobjects.scm @@ -1,25 +1,58 @@ (class_declaration - body: (class_body . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) @class.outer + body: (class_body + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) @class.outer (class_declaration - body: (enum_class_body . "{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) @class.outer + body: (enum_class_body + . + "{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) @class.outer (function_declaration - body: (function_body . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) @function.outer + body: (function_body + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) @function.outer (lambda_literal - ("{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) @function.outer + ("{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) @function.outer (call_suffix - (value_arguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) @call.outer + (value_arguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) @call.outer (value_argument - value: ((_) @parameter.inner)) @parameter.outer + value: (_) @parameter.inner) @parameter.outer (comment) @comment.outer diff --git a/queries/terraform/textobjects.scm b/queries/terraform/textobjects.scm new file mode 100644 index 0000000..8e7fa7e --- /dev/null +++ b/queries/terraform/textobjects.scm @@ -0,0 +1,2 @@ +; inherits: hcl + diff --git a/queries/toml/textobjects.scm b/queries/toml/textobjects.scm index 7dd39af..4b0b973 100644 --- a/queries/toml/textobjects.scm +++ b/queries/toml/textobjects.scm @@ -3,3 +3,32 @@ (float) ] @number.inner +(table + (pair) @parameter.inner @parameter.outer) + +((inline_table + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + +((inline_table + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + +((array + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + +((array + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) + diff --git a/queries/twig/textobjects.scm b/queries/twig/textobjects.scm index b4a8f47..e266505 100644 --- a/queries/twig/textobjects.scm +++ b/queries/twig/textobjects.scm @@ -1,26 +1,33 @@ -;; comments +; comments (comment) @comment.outer -;; statement +; statement (statement_directive) @statement.outer -;; @parameter +; @parameter (arguments - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end ) + (arguments - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end ) (parameters - "," @parameter.outer._start . + "," @parameter.outer._start + . (_) @parameter.inner @parameter.outer._end ) + (parameters - . (_) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end ) - diff --git a/queries/typescript/textobjects.scm b/queries/typescript/textobjects.scm index 3c3c3a7..5033b9e 100644 --- a/queries/typescript/textobjects.scm +++ b/queries/typescript/textobjects.scm @@ -3,18 +3,39 @@ (interface_declaration) @class.outer (interface_declaration - body: (object_type . "{" . (_) @class.inner._start @class.inner._end _? @class.inner._end . "}" - )) + body: (interface_body + . + "{" + . + (_) @class.inner._start @class.inner._end + _? @class.inner._end + . + "}" + )) (type_alias_declaration) @class.outer (type_alias_declaration - value: (object_type . "{" . (_) @class.inner._start @class.inner._end _? @class.inner._end . "}" - )) + value: (object_type + . + "{" + . + (_) @class.inner._start @class.inner._end + _? @class.inner._end + . + "}" + )) (enum_declaration) @class.outer (enum_declaration - body: (enum_body . "{" . (_) @class.inner._start @class.inner._end _? @class.inner._end . "}" - )) + body: (enum_body + . + "{" + . + (_) @class.inner._start @class.inner._end + _? @class.inner._end + . + "}" + )) diff --git a/queries/v/textobjects.scm b/queries/v/textobjects.scm index b5fccca..1fa0c29 100644 --- a/queries/v/textobjects.scm +++ b/queries/v/textobjects.scm @@ -1,63 +1,113 @@ -;; assignment -[(var_declaration +; assignment +[ + (var_declaration var_list: (_) @assignment.lhs expression_list: (_)* @assignment.rhs) (assignment_statement left: (_) @assignment.lhs - right: (_)* @assignment.rhs)] + right: (_)* @assignment.rhs) +] -[(var_declaration +[ + (var_declaration var_list: (_) @assignment.inner) (assignment_statement - left: (_) @assignment.inner)] + left: (_) @assignment.inner) +] -[(var_declaration +[ + (var_declaration expression_list: (_) @assignment.inner) (assignment_statement - right: (_) @assignment.inner)] - -;; block -(_ (block . "{" . (_) @block.inner._start @block.inner._end (_)? @block.inner._end . "}") - ) @block.outer - -;; call + right: (_) @assignment.inner) +] + +; block +(_ + (block + . + "{" + . + (_) @block.inner._start @block.inner._end + (_)? @block.inner._end + . + "}") + ) @block.outer + +; call (call_expression) @call.outer -(call_expression - arguments: (argument_list . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) -;; class: structs +(call_expression + arguments: (argument_list + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + )) + +; class: structs (struct_declaration - ("{" . (_) @class.inner._start @class.inner._end (_)? @class.inner._end . "}" - )) + ("{" + . + (_) @class.inner._start @class.inner._end + (_)? @class.inner._end + . + "}" + )) (struct_declaration) @class.outer -;; comment +; comment ; leave space after comment marker if there is one -((comment) @comment.inner @comment.outer - (#offset! @comment.inner 0 3 0) - (#match? @comment.outer "// .*")) +((line_comment) @comment.inner @comment.outer + (#offset! @comment.inner 0 3 0) + (#match? @comment.outer "// .*")) ; else remove everything accept comment marker -((comment) @comment.inner @comment.outer +((line_comment) @comment.inner @comment.outer (#offset! @comment.inner 0 2 0)) -;; conditional +(block_comment) @comment.inner @comment.outer + +; conditional (if_expression - block: (block . "{" . (_) @conditional.inner._start @conditional.inner._end (_)? @conditional.inner._end . "}" + block: (block + . + "{" + . + (_) @conditional.inner._start @conditional.inner._end + (_)? @conditional.inner._end + . + "}" )?) @conditional.outer -;; function +; function (function_declaration - body: (block . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (block + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) (function_declaration) @function.outer -;; loop +; loop (for_statement - body: (block . "{" . (_) @loop.inner._start @loop.inner._end (_)? @loop.inner._end . "}" + body: (block + . + "{" + . + (_) @loop.inner._start @loop.inner._end + (_)? @loop.inner._end + . + "}" )?) @loop.outer [ @@ -65,20 +115,25 @@ (float_literal) ] @number.inner -;; parameter +; parameter (parameter_list - "," @parameter.outer._start . + "," @parameter.outer._start + . (parameter_declaration) @parameter.inner @parameter.outer._end - ) + ) (parameter_list - . (parameter_declaration) @parameter.inner @parameter.outer._start - . ","? @parameter.outer._end - ) - -;; return -(return_statement (_)* @return.inner) @return.outer - -;; statements -(block (_) @statement.outer) + . + (parameter_declaration) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end + ) + +; return +(return_statement + (_)* @return.inner) @return.outer + +; statements +(block + (_) @statement.outer) diff --git a/queries/verilog/textobjects.scm b/queries/verilog/textobjects.scm index 2331d57..9bccf7c 100644 --- a/queries/verilog/textobjects.scm +++ b/queries/verilog/textobjects.scm @@ -14,7 +14,5 @@ (always_construct) @block.outer -[ - (module_declaration) -] @class.outer +(module_declaration) @class.outer diff --git a/queries/vim/textobjects.scm b/queries/vim/textobjects.scm index d629042..825a495 100644 --- a/queries/vim/textobjects.scm +++ b/queries/vim/textobjects.scm @@ -1,30 +1,47 @@ (comment) @comment.outer -(function_definition (body) @function.inner) @function.outer +(function_definition + (body) @function.inner) @function.outer -(parameters (identifier) @parameter.inner) +(parameters + (identifier) @parameter.inner) -((parameters "," @parameter.outer._start . (identifier) @parameter.outer._end) - ) +((parameters + "," @parameter.outer._start + . + (identifier) @parameter.outer._end) + ) -((parameters . (identifier) @parameter.outer._start . "," @parameter.outer._end) - ) +((parameters + . + (identifier) @parameter.outer._start + . + "," @parameter.outer._end) + ) -(if_statement (body) @conditional.inner) @conditional.outer -(for_loop (body) @loop.inner) @loop.outer -(while_loop (body) @loop.inner) @loop.outer +(if_statement + (body) @conditional.inner) @conditional.outer + +(for_loop + (body) @loop.inner) @loop.outer + +(while_loop + (body) @loop.inner) @loop.outer (call_expression) @call.outer (return_statement (_)? @return.inner) @return.outer -(_ (body) @block.inner) @block.outer -(body (_) @statement.outer) +(_ + (body) @block.inner) @block.outer + +(body + (_) @statement.outer) ((syntax_statement - (pattern) @regex.inner @regex.outer) - (#offset! @regex.outer 0 -1 0 1)) + (pattern) @regex.inner @regex.outer) + (#offset! @regex.outer 0 -1 0 1)) [ (integer_literal) diff --git a/queries/vue/textobjects.scm b/queries/vue/textobjects.scm index cbcd246..c9c5f7f 100644 --- a/queries/vue/textobjects.scm +++ b/queries/vue/textobjects.scm @@ -1,7 +1,9 @@ (element) @function.outer + [ (attribute) (directive_attribute) ] @call.outer + (attribute_value) @parameter.outer diff --git a/queries/wgsl/textobjects.scm b/queries/wgsl/textobjects.scm index 434cf40..397b9f4 100644 --- a/queries/wgsl/textobjects.scm +++ b/queries/wgsl/textobjects.scm @@ -1,43 +1,68 @@ (function_declaration) @function.outer (function_declaration - body: (compound_statement . "{" . (_) @function.inner._start @function.inner._end (_)? @function.inner._end . "}" - )) + body: (compound_statement + . + "{" + . + (_) @function.inner._start @function.inner._end + (_)? @function.inner._end + . + "}" + )) ((parameter_list - "," @parameter.outer._start . (parameter) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (parameter) @parameter.inner @parameter.outer._end) + ) + ((parameter_list - . (parameter) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (parameter) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) (compound_statement) @block.outer ; loops (loop_statement (_)? @loop.inner) @loop.outer + (for_statement (_)? @loop.inner) @loop.outer + (while_statement (_)? @loop.inner) @loop.outer ((struct_declaration - "{" . _ @class.inner._start _ @class.inner._end . "}") @class.outer - ) + "{" + . + _ @class.inner._start + _ @class.inner._end + . + "}") @class.outer + ) ; conditional (if_statement consequence: (_)? @conditional.inner - alternative: (_)? @conditional.inner - ) @conditional.outer + alternative: (_)? @conditional.inner) @conditional.outer (if_statement condition: (_) @conditional.inner) ((argument_list_expression - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((argument_list_expression - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) diff --git a/queries/yaml/textobjects.scm b/queries/yaml/textobjects.scm index e0083e9..15d2428 100644 --- a/queries/yaml/textobjects.scm +++ b/queries/yaml/textobjects.scm @@ -1,4 +1,4 @@ -;; assignment, statement +; assignment, statement (block_mapping_pair key: (_) @assignment.lhs value: (_) @assignment.rhs) @assignment.outer @statement.outer @@ -9,20 +9,19 @@ (block_mapping_pair value: (_) @assignment.inner) -;; comment +; comment ; leave space after comment marker if there is one ((comment) @comment.inner @comment.outer - (#offset! @comment.inner 0 2 0) - (#match? @comment.outer "# .*")) + (#offset! @comment.inner 0 2 0) + (#match? @comment.outer "# .*")) ; else remove everything accept comment marker ((comment) @comment.inner @comment.outer (#offset! @comment.inner 0 1 0)) -;; number +; number [ (integer_scalar) (float_scalar) ] @number.inner - diff --git a/queries/zig/textobjects.scm b/queries/zig/textobjects.scm index 60702db..9f49b77 100644 --- a/queries/zig/textobjects.scm +++ b/queries/zig/textobjects.scm @@ -1,13 +1,15 @@ -;; "Classes" -(VarDecl - (_ (_ (ContainerDecl) @class.inner))) @class.outer +; "Classes" +(VarDecl + (_ + (_ + (ContainerDecl) @class.inner))) @class.outer -;; functions -(_ +; functions +(_ (FnProto) (Block) @function.inner) @function.outer -;; loops +; loops (_ (ForPrefix) (_) @loop.inner) @loop.outer @@ -16,44 +18,68 @@ (WhilePrefix) (_) @loop.inner) @loop.outer -;; blocks -(_ (Block) @block.inner) @block.outer +; blocks +(_ + (Block) @block.inner) @block.outer -;; statements +; statements (Statement) @statement.outer -;; parameters -((ParamDeclList - "," @parameter.outer._start . (ParamDecl) @parameter.inner @parameter.outer._end) - ) +; parameters +((ParamDeclList + "," @parameter.outer._start + . + (ParamDecl) @parameter.inner @parameter.outer._end) + ) + ((ParamDeclList - . (ParamDecl) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (ParamDecl) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) -;; arguments +; arguments ((FnCallArguments - "," @parameter.outer._start . (_) @parameter.inner @parameter.outer._end) - ) + "," @parameter.outer._start + . + (_) @parameter.inner @parameter.outer._end) + ) + ((FnCallArguments - . (_) @parameter.inner @parameter.outer._start . ","? @parameter.outer._end) - ) + . + (_) @parameter.inner @parameter.outer._start + . + ","? @parameter.outer._end) + ) -;; comments +; comments (doc_comment) @comment.outer + (line_comment) @comment.outer -;; conditionals +; conditionals (_ (IfPrefix) (_) @conditional.inner) @conditional.outer ((SwitchExpr - "{" @conditional.inner._start "}" @conditional.inner._end) - ) @conditional.outer + "{" @conditional.inner._start + "}" @conditional.inner._end) + ) @conditional.outer + +; calls +(_ + (FnCallArguments)) @call.outer -;; calls -(_ (FnCallArguments)) @call.outer (_ - (FnCallArguments . "(" . (_) @call.inner._start (_)? @call.inner._end . ")" - )) + (FnCallArguments + . + "(" + . + (_) @call.inner._start + (_)? @call.inner._end + . + ")" + ))