Add textobject for entries/elements of list-like things (#8150)
This commit is contained in:
parent
47ef9f0ca2
commit
1abb64e48d
17 changed files with 145 additions and 3 deletions
|
@ -69,7 +69,7 @@
|
||||||
| gomod | ✓ | | | `gopls` |
|
| gomod | ✓ | | | `gopls` |
|
||||||
| gotmpl | ✓ | | | `gopls` |
|
| gotmpl | ✓ | | | `gopls` |
|
||||||
| gowork | ✓ | | | `gopls` |
|
| gowork | ✓ | | | `gopls` |
|
||||||
| graphql | ✓ | | | `graphql-lsp` |
|
| graphql | ✓ | ✓ | | `graphql-lsp` |
|
||||||
| groovy | ✓ | | | |
|
| groovy | ✓ | | | |
|
||||||
| hare | ✓ | | | |
|
| hare | ✓ | | | |
|
||||||
| haskell | ✓ | ✓ | | `haskell-language-server-wrapper` |
|
| haskell | ✓ | ✓ | | `haskell-language-server-wrapper` |
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
| javascript | ✓ | ✓ | ✓ | `typescript-language-server` |
|
| javascript | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||||
| jinja | ✓ | | | |
|
| jinja | ✓ | | | |
|
||||||
| jsdoc | ✓ | | | |
|
| jsdoc | ✓ | | | |
|
||||||
| json | ✓ | | ✓ | `vscode-json-language-server` |
|
| json | ✓ | ✓ | ✓ | `vscode-json-language-server` |
|
||||||
| json5 | ✓ | | | |
|
| json5 | ✓ | | | |
|
||||||
| jsonc | ✓ | | ✓ | `vscode-json-language-server` |
|
| jsonc | ✓ | | ✓ | `vscode-json-language-server` |
|
||||||
| jsonnet | ✓ | | | `jsonnet-language-server` |
|
| jsonnet | ✓ | | | `jsonnet-language-server` |
|
||||||
|
@ -188,7 +188,7 @@
|
||||||
| templ | ✓ | | | `templ` |
|
| templ | ✓ | | | `templ` |
|
||||||
| tfvars | ✓ | | ✓ | `terraform-ls` |
|
| tfvars | ✓ | | ✓ | `terraform-ls` |
|
||||||
| todotxt | ✓ | | | |
|
| todotxt | ✓ | | | |
|
||||||
| toml | ✓ | | | `taplo` |
|
| toml | ✓ | ✓ | | `taplo` |
|
||||||
| tsq | ✓ | | | |
|
| tsq | ✓ | | | |
|
||||||
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
|
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
|
||||||
| twig | ✓ | | | |
|
| twig | ✓ | | | |
|
||||||
|
|
|
@ -25,6 +25,8 @@ The following [captures][tree-sitter-captures] are recognized:
|
||||||
| `parameter.inside` |
|
| `parameter.inside` |
|
||||||
| `comment.inside` |
|
| `comment.inside` |
|
||||||
| `comment.around` |
|
| `comment.around` |
|
||||||
|
| `entry.inside` |
|
||||||
|
| `entry.around` |
|
||||||
|
|
||||||
[Example query files][textobject-examples] can be found in the helix GitHub repository.
|
[Example query files][textobject-examples] can be found in the helix GitHub repository.
|
||||||
|
|
||||||
|
|
|
@ -475,6 +475,8 @@ impl MappableCommand {
|
||||||
goto_prev_comment, "Goto previous comment",
|
goto_prev_comment, "Goto previous comment",
|
||||||
goto_next_test, "Goto next test",
|
goto_next_test, "Goto next test",
|
||||||
goto_prev_test, "Goto previous test",
|
goto_prev_test, "Goto previous test",
|
||||||
|
goto_next_entry, "Goto next pairing",
|
||||||
|
goto_prev_entry, "Goto previous pairing",
|
||||||
goto_next_paragraph, "Goto next paragraph",
|
goto_next_paragraph, "Goto next paragraph",
|
||||||
goto_prev_paragraph, "Goto previous paragraph",
|
goto_prev_paragraph, "Goto previous paragraph",
|
||||||
dap_launch, "Launch debug target",
|
dap_launch, "Launch debug target",
|
||||||
|
@ -5167,6 +5169,14 @@ fn goto_prev_test(cx: &mut Context) {
|
||||||
goto_ts_object_impl(cx, "test", Direction::Backward)
|
goto_ts_object_impl(cx, "test", Direction::Backward)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn goto_next_entry(cx: &mut Context) {
|
||||||
|
goto_ts_object_impl(cx, "entry", Direction::Forward)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn goto_prev_entry(cx: &mut Context) {
|
||||||
|
goto_ts_object_impl(cx, "entry", Direction::Backward)
|
||||||
|
}
|
||||||
|
|
||||||
fn select_textobject_around(cx: &mut Context) {
|
fn select_textobject_around(cx: &mut Context) {
|
||||||
select_textobject(cx, textobject::TextObject::Around);
|
select_textobject(cx, textobject::TextObject::Around);
|
||||||
}
|
}
|
||||||
|
@ -5231,6 +5241,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
||||||
'a' => textobject_treesitter("parameter", range),
|
'a' => textobject_treesitter("parameter", range),
|
||||||
'c' => textobject_treesitter("comment", range),
|
'c' => textobject_treesitter("comment", range),
|
||||||
'T' => textobject_treesitter("test", range),
|
'T' => textobject_treesitter("test", range),
|
||||||
|
'e' => textobject_treesitter("entry", range),
|
||||||
'p' => textobject::textobject_paragraph(text, range, objtype, count),
|
'p' => textobject::textobject_paragraph(text, range, objtype, count),
|
||||||
'm' => textobject::textobject_pair_surround_closest(
|
'm' => textobject::textobject_pair_surround_closest(
|
||||||
text, range, objtype, count,
|
text, range, objtype, count,
|
||||||
|
@ -5263,6 +5274,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
|
||||||
("a", "Argument/parameter (tree-sitter)"),
|
("a", "Argument/parameter (tree-sitter)"),
|
||||||
("c", "Comment (tree-sitter)"),
|
("c", "Comment (tree-sitter)"),
|
||||||
("T", "Test (tree-sitter)"),
|
("T", "Test (tree-sitter)"),
|
||||||
|
("e", "Data structure entry (tree-sitter)"),
|
||||||
("m", "Closest surrounding pair"),
|
("m", "Closest surrounding pair"),
|
||||||
(" ", "... or any character acting as a pair"),
|
(" ", "... or any character acting as a pair"),
|
||||||
];
|
];
|
||||||
|
|
|
@ -114,6 +114,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
||||||
"t" => goto_prev_class,
|
"t" => goto_prev_class,
|
||||||
"a" => goto_prev_parameter,
|
"a" => goto_prev_parameter,
|
||||||
"c" => goto_prev_comment,
|
"c" => goto_prev_comment,
|
||||||
|
"e" => goto_prev_entry,
|
||||||
"T" => goto_prev_test,
|
"T" => goto_prev_test,
|
||||||
"p" => goto_prev_paragraph,
|
"p" => goto_prev_paragraph,
|
||||||
"space" => add_newline_above,
|
"space" => add_newline_above,
|
||||||
|
@ -127,6 +128,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
||||||
"t" => goto_next_class,
|
"t" => goto_next_class,
|
||||||
"a" => goto_next_parameter,
|
"a" => goto_next_parameter,
|
||||||
"c" => goto_next_comment,
|
"c" => goto_next_comment,
|
||||||
|
"e" => goto_next_entry,
|
||||||
"T" => goto_next_test,
|
"T" => goto_next_test,
|
||||||
"p" => goto_next_paragraph,
|
"p" => goto_next_paragraph,
|
||||||
"space" => add_newline_below,
|
"space" => add_newline_below,
|
||||||
|
|
|
@ -4,3 +4,9 @@
|
||||||
(type_alias_declaration
|
(type_alias_declaration
|
||||||
value: (_) @class.inside)
|
value: (_) @class.inside)
|
||||||
] @class.around
|
] @class.around
|
||||||
|
|
||||||
|
(enum_body
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(enum_assignment (_) @entry.inside)
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,6 @@
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
|
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(array
|
||||||
|
(_) @entry.around)
|
||||||
|
|
|
@ -19,3 +19,9 @@
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
|
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(enumerator
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(initializer_list
|
||||||
|
(_) @entry.around)
|
||||||
|
|
|
@ -34,3 +34,12 @@
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
|
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(array
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(pair
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(pair_pattern
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
23
runtime/queries/graphql/textobjects.scm
Normal file
23
runtime/queries/graphql/textobjects.scm
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
(type_definition) @class.around
|
||||||
|
|
||||||
|
(executable_definition) @function.around
|
||||||
|
|
||||||
|
(arguments_definition
|
||||||
|
(input_value_definition) @parameter.inside @parameter.movement)
|
||||||
|
|
||||||
|
(arguments
|
||||||
|
(argument) @parameter.inside @parameter.movement)
|
||||||
|
|
||||||
|
(selection
|
||||||
|
[(field) (fragment_spread)] @entry.around)
|
||||||
|
|
||||||
|
(selection
|
||||||
|
(field (selection_set) @entry.inside))
|
||||||
|
|
||||||
|
(field_definition
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(input_fields_definition
|
||||||
|
(input_value_definition ) @entry.around)
|
||||||
|
|
||||||
|
(enum_value) @entry.around
|
|
@ -36,3 +36,9 @@
|
||||||
(line_comment)+ @comment.around
|
(line_comment)+ @comment.around
|
||||||
|
|
||||||
(block_comment) @comment.around
|
(block_comment) @comment.around
|
||||||
|
|
||||||
|
(array_initializer
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(enum_body
|
||||||
|
(enum_constant) @entry.around)
|
||||||
|
|
5
runtime/queries/json/textobjects.scm
Normal file
5
runtime/queries/json/textobjects.scm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
(pair
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(array
|
||||||
|
(_) @entry.around)
|
|
@ -13,3 +13,6 @@
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
|
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(table_constructor
|
||||||
|
(field (_) @entry.inside) @entry.around)
|
||||||
|
|
|
@ -38,3 +38,15 @@
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
|
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(array_creation_expression
|
||||||
|
(array_element_initializer
|
||||||
|
(_) @entry.inside
|
||||||
|
) @entry.around @entry.movement)
|
||||||
|
|
||||||
|
(list_literal
|
||||||
|
(_) @entry.inside @entry.around @entry.movement)
|
||||||
|
|
||||||
|
[
|
||||||
|
(enum_case)
|
||||||
|
] @entry.around @entry.movement
|
||||||
|
|
|
@ -21,3 +21,15 @@
|
||||||
name: (identifier) @_name
|
name: (identifier) @_name
|
||||||
body: (block)? @test.inside) @test.around
|
body: (block)? @test.inside) @test.around
|
||||||
(#match? @_name "^test_"))
|
(#match? @_name "^test_"))
|
||||||
|
|
||||||
|
(list
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(tuple
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(set
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(pair
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
|
@ -42,3 +42,15 @@
|
||||||
; Comments
|
; Comments
|
||||||
(comment) @comment.inside
|
(comment) @comment.inside
|
||||||
(comment)+ @comment.around
|
(comment)+ @comment.around
|
||||||
|
|
||||||
|
(pair
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(array
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(string_array
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(symbol_array
|
||||||
|
(_) @entry.around)
|
||||||
|
|
|
@ -59,3 +59,27 @@
|
||||||
(function_item
|
(function_item
|
||||||
body: (_) @test.inside) @test.around
|
body: (_) @test.inside) @test.around
|
||||||
(#eq? @_test_attribute "test"))
|
(#eq? @_test_attribute "test"))
|
||||||
|
|
||||||
|
(array_expression
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(tuple_expression
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
(tuple_pattern
|
||||||
|
(_) @entry.around)
|
||||||
|
|
||||||
|
; Commonly used vec macro intializer is special cased
|
||||||
|
(macro_invocation
|
||||||
|
(identifier) @_id (token_tree (_) @entry.around)
|
||||||
|
(#eq? @_id "vec"))
|
||||||
|
|
||||||
|
(enum_variant) @entry.around
|
||||||
|
|
||||||
|
(field_declaration
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(field_initializer
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(shorthand_field_initializer) @entry.around
|
||||||
|
|
5
runtime/queries/toml/textobjects.scm
Normal file
5
runtime/queries/toml/textobjects.scm
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
(pair
|
||||||
|
(_) @entry.inside) @entry.around
|
||||||
|
|
||||||
|
(array
|
||||||
|
(_) @entry.around)
|
Loading…
Add table
Reference in a new issue