mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 03:40:04 -04:00
go loop and func literal, rust textobject support
This commit is contained in:
parent
ac14bad7a8
commit
59c084b5d8
2 changed files with 88 additions and 2 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
(function_declaration
|
(function_declaration
|
||||||
body: (block)? @function.inner) @function.outer
|
body: (block)? @function.inner) @function.outer
|
||||||
|
|
||||||
|
;; function literals
|
||||||
|
(func_literal
|
||||||
|
(_)? @function.inner) @function.outer
|
||||||
|
|
||||||
;; method as function textobject
|
;; method as function textobject
|
||||||
(method_declaration
|
(method_declaration
|
||||||
body: (block)? @function.inner) @function.outer
|
body: (block)? @function.inner) @function.outer
|
||||||
|
|
@ -14,8 +18,8 @@
|
||||||
(type_spec (type_identifier) (interface_type (method_spec_list (_)?) @class.inner))) @class.outer
|
(type_spec (type_identifier) (interface_type (method_spec_list (_)?) @class.inner))) @class.outer
|
||||||
|
|
||||||
;; struct literals as class textobject
|
;; struct literals as class textobject
|
||||||
(composite_literal
|
(composite_literal
|
||||||
(type_identifier)?
|
(type_identifier)?
|
||||||
(struct_type (_))?
|
(struct_type (_))?
|
||||||
(literal_value (_)) @class.inner) @class.outer
|
(literal_value (_)) @class.inner) @class.outer
|
||||||
|
|
||||||
|
|
@ -29,9 +33,18 @@
|
||||||
(if_statement
|
(if_statement
|
||||||
condition: (_) @conditional.inner)
|
condition: (_) @conditional.inner)
|
||||||
|
|
||||||
|
;; loops
|
||||||
|
(for_statement
|
||||||
|
body: (block)? @loop.inner) @loop.outer
|
||||||
|
|
||||||
;; blocks
|
;; blocks
|
||||||
(_ (block) @block.inner) @block.outer
|
(_ (block) @block.inner) @block.outer
|
||||||
|
|
||||||
;; statements
|
;; statements
|
||||||
(block (_) @statement.outer)
|
(block (_) @statement.outer)
|
||||||
|
|
||||||
;; comments
|
;; comments
|
||||||
(comment) @comment.outer
|
(comment) @comment.outer
|
||||||
|
|
||||||
|
;; calls
|
||||||
|
(call_expression (_)? @call.inner) @call.outer
|
||||||
|
|
|
||||||
73
queries/rust/textobjects.scm
Normal file
73
queries/rust/textobjects.scm
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
;; functions
|
||||||
|
(function_item
|
||||||
|
(_) @function.inner) @function.outer
|
||||||
|
|
||||||
|
;; quantifies as class(es)
|
||||||
|
(struct_item
|
||||||
|
(_) @class.inner) @class.outer
|
||||||
|
|
||||||
|
(enum_item
|
||||||
|
(_) @class.inner) @class.outer
|
||||||
|
|
||||||
|
(union_item
|
||||||
|
(_) @class.inner) @class.outer
|
||||||
|
|
||||||
|
(trait_item
|
||||||
|
(_) @class.inner) @class.outer
|
||||||
|
|
||||||
|
(impl_item
|
||||||
|
(_) @class.inner) @class.outer
|
||||||
|
|
||||||
|
;; conditionals
|
||||||
|
(if_expression
|
||||||
|
alternative: (_ (_)? @conditional.inner)?
|
||||||
|
) @conditional.outer
|
||||||
|
|
||||||
|
(if_expression
|
||||||
|
alternative: (block)? @conditional.inner)
|
||||||
|
|
||||||
|
(if_expression
|
||||||
|
condition: (_) @conditional.inner)
|
||||||
|
|
||||||
|
(if_expression
|
||||||
|
consequence: (block)? @conditional.inner)
|
||||||
|
|
||||||
|
(match_arm
|
||||||
|
(_)) @conditional.inner
|
||||||
|
|
||||||
|
(match_expression
|
||||||
|
(match_arm)?
|
||||||
|
) @conditional.outer
|
||||||
|
|
||||||
|
(if_let_expression
|
||||||
|
consequence: (block)?
|
||||||
|
@conditional.inner) @conditional.outer
|
||||||
|
|
||||||
|
(if_let_expression
|
||||||
|
alternative: (block)? @conditional.inner)
|
||||||
|
|
||||||
|
(if_let_expression
|
||||||
|
condition: (_) @conditional.inner)
|
||||||
|
|
||||||
|
;; loops
|
||||||
|
(loop_expression
|
||||||
|
(_)? @loop.inner) @loop.outer
|
||||||
|
|
||||||
|
(while_expression
|
||||||
|
(_)? @loop.inner) @loop.outer
|
||||||
|
|
||||||
|
(while_let_expression
|
||||||
|
(_)? @loop.inner) @loop.outer
|
||||||
|
|
||||||
|
(for_expression
|
||||||
|
body: (block)? @loop.inner) @loop.outer
|
||||||
|
|
||||||
|
;; blocks
|
||||||
|
(_ (block) @block.inner) @block.outer
|
||||||
|
(unsafe_block (_)? @block.inner) @block.outer
|
||||||
|
|
||||||
|
;; calls
|
||||||
|
(call_expression (_)? @call.inner) @call.outer
|
||||||
|
|
||||||
|
;; statements
|
||||||
|
(block (_) @statement.outer)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue