Add textobjects queries (#20924)
Co-Authored-By: Max <max@zed.dev> Release Notes: - vim: Added motions `[[`, `[]`, `]]`, `][` for navigating by section, `[m`, `]m`, `[M`, `]M` for navigating by method, and `[*`, `]*`, `[/`, `]/` for comments. These currently only work for languages built in to Zed, as they are powered by new tree-sitter queries. - vim: Added new text objects: `ic`, `ac` for inside/around classes, `if`,`af` for functions/methods, and `g c` for comments. These currently only work for languages built in to Zed, as they are powered by new tree-sitter queries. --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
c443307c19
commit
75c9dc179b
28 changed files with 1205 additions and 26 deletions
7
crates/languages/src/bash/textobjects.scm
Normal file
7
crates/languages/src/bash/textobjects.scm
Normal file
|
@ -0,0 +1,7 @@
|
|||
(function_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
|
||||
(comment) @comment.around
|
25
crates/languages/src/c/textobjects.scm
Normal file
25
crates/languages/src/c/textobjects.scm
Normal file
|
@ -0,0 +1,25 @@
|
|||
(declaration
|
||||
declarator: (function_declarator)) @function.around
|
||||
|
||||
(function_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
|
||||
(preproc_function_def
|
||||
value: (_) @function.inside) @function.around
|
||||
|
||||
(comment) @comment.around
|
||||
|
||||
(struct_specifier
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}")) @class.around
|
||||
|
||||
(enum_specifier
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}")) @class.around
|
31
crates/languages/src/cpp/textobjects.scm
Normal file
31
crates/languages/src/cpp/textobjects.scm
Normal file
|
@ -0,0 +1,31 @@
|
|||
(declaration
|
||||
declarator: (function_declarator)) @function.around
|
||||
|
||||
(function_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
|
||||
(preproc_function_def
|
||||
value: (_) @function.inside) @function.around
|
||||
|
||||
(comment) @comment.around
|
||||
|
||||
(struct_specifier
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}")) @class.around
|
||||
|
||||
(enum_specifier
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}")) @class.around
|
||||
|
||||
(class_specifier
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ":"? ";"?]* @class.inside
|
||||
"}"?)) @class.around
|
30
crates/languages/src/css/textobjects.scm
Normal file
30
crates/languages/src/css/textobjects.scm
Normal file
|
@ -0,0 +1,30 @@
|
|||
(comment) @comment.around
|
||||
|
||||
(rule_set
|
||||
(block (
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" ))) @function.around
|
||||
(keyframe_block
|
||||
(block (
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" ))) @function.around
|
||||
|
||||
(media_statement
|
||||
(block (
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}" ))) @class.around
|
||||
|
||||
(supports_statement
|
||||
(block (
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}" ))) @class.around
|
||||
|
||||
(keyframes_statement
|
||||
(keyframe_block_list (
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}" ))) @class.around
|
25
crates/languages/src/go/textobjects.scm
Normal file
25
crates/languages/src/go/textobjects.scm
Normal file
|
@ -0,0 +1,25 @@
|
|||
(function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(method_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(type_declaration
|
||||
(type_spec (struct_type (field_declaration_list (
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}")?)))) @class.around
|
||||
|
||||
(type_declaration
|
||||
(type_spec (interface_type
|
||||
(_)* @class.inside))) @class.around
|
||||
|
||||
(type_declaration) @class.around
|
||||
|
||||
(comment)+ @comment.around
|
51
crates/languages/src/javascript/textobjects.scm
Normal file
51
crates/languages/src/javascript/textobjects.scm
Normal file
|
@ -0,0 +1,51 @@
|
|||
(comment)+ @comment.around
|
||||
|
||||
(function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(method_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(function_expression
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function
|
||||
body: (statement_block
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function) @function.around
|
||||
|
||||
(generator_function
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(generator_function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(class_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(class
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
1
crates/languages/src/json/textobjects.scm
Normal file
1
crates/languages/src/json/textobjects.scm
Normal file
|
@ -0,0 +1 @@
|
|||
(comment)+ @comment.around
|
1
crates/languages/src/jsonc/textobjects.scm
Normal file
1
crates/languages/src/jsonc/textobjects.scm
Normal file
|
@ -0,0 +1 @@
|
|||
(comment)+ @comment.around
|
3
crates/languages/src/markdown/textobjects.scm
Normal file
3
crates/languages/src/markdown/textobjects.scm
Normal file
|
@ -0,0 +1,3 @@
|
|||
(section
|
||||
(atx_heading)
|
||||
(_)* @class.inside) @class.around
|
7
crates/languages/src/python/textobjects.scm
Normal file
7
crates/languages/src/python/textobjects.scm
Normal file
|
@ -0,0 +1,7 @@
|
|||
(comment)+ @comment.around
|
||||
|
||||
(function_definition
|
||||
body: (_) @function.inside) @function.around
|
||||
|
||||
(class_definition
|
||||
body: (_) @class.inside) @class.around
|
|
@ -15,11 +15,7 @@
|
|||
(visibility_modifier)? @context
|
||||
name: (_) @name) @item
|
||||
|
||||
(impl_item
|
||||
"impl" @context
|
||||
trait: (_)? @name
|
||||
"for"? @context
|
||||
type: (_) @name
|
||||
(function_item
|
||||
body: (_ "{" @open (_)* "}" @close)) @item
|
||||
|
||||
(trait_item
|
||||
|
|
51
crates/languages/src/rust/textobjects.scm
Normal file
51
crates/languages/src/rust/textobjects.scm
Normal file
|
@ -0,0 +1,51 @@
|
|||
; functions
|
||||
(function_signature_item) @function.around
|
||||
|
||||
(function_item
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}" )) @function.around
|
||||
|
||||
; classes
|
||||
(struct_item
|
||||
body: (_
|
||||
["{" "("]?
|
||||
[(_) ","?]* @class.inside
|
||||
["}" ")"]? )) @class.around
|
||||
|
||||
(enum_item
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(union_item
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(trait_item
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(impl_item
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(mod_item
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
; comments
|
||||
|
||||
(line_comment)+ @comment.around
|
||||
|
||||
(block_comment) @comment.around
|
79
crates/languages/src/tsx/textobjects.scm
Normal file
79
crates/languages/src/tsx/textobjects.scm
Normal file
|
@ -0,0 +1,79 @@
|
|||
(comment)+ @comment.around
|
||||
|
||||
(function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(method_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(function_expression
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function
|
||||
body: (statement_block
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function) @function.around
|
||||
(function_signature) @function.around
|
||||
|
||||
(generator_function
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(generator_function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(class_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(class
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(interface_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(enum_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(ambient_declaration
|
||||
(module
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" ))) @class.around
|
||||
|
||||
(internal_module
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(type_alias_declaration) @class.around
|
79
crates/languages/src/typescript/textobjects.scm
Normal file
79
crates/languages/src/typescript/textobjects.scm
Normal file
|
@ -0,0 +1,79 @@
|
|||
(comment)+ @comment.around
|
||||
|
||||
(function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(method_definition
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(function_expression
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function
|
||||
body: (statement_block
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(arrow_function) @function.around
|
||||
(function_signature) @function.around
|
||||
|
||||
(generator_function
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(generator_function_declaration
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @function.inside
|
||||
"}")) @function.around
|
||||
|
||||
(class_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(class
|
||||
body: (_
|
||||
"{"
|
||||
(_)* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(interface_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(enum_declaration
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ","?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(ambient_declaration
|
||||
(module
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" ))) @class.around
|
||||
|
||||
(internal_module
|
||||
body: (_
|
||||
"{"
|
||||
[(_) ";"?]* @class.inside
|
||||
"}" )) @class.around
|
||||
|
||||
(type_alias_declaration) @class.around
|
1
crates/languages/src/yaml/textobjects.scm
Normal file
1
crates/languages/src/yaml/textobjects.scm
Normal file
|
@ -0,0 +1 @@
|
|||
(comment)+ @comment
|
Loading…
Add table
Add a link
Reference in a new issue