on master help sign in
Rename extend indent captures.

Clarify comments in indent code.

commit081327695f7d4740f8a66bf2da75905656f70a58 authorDaniel Ebert <daniel.ebert@protonmail.com> dateSat 8 Oct 2022, 11:04 (4 years ago) parentdc44348
3 files changed+15−15
book/src/guides/indent.md+3−3 helix-core/src/indent.rs+10−10 runtime/queries/python/indents.scm+2−2
book/src/guides/indent.md+3−3
@@ -46,16 +46,16 @@ capture on the same line, the indent level isn't changed at all.
4646- `@outdent` (default scope `all`):
4747Decrease the indent level by 1. The same rules as for `@indent` apply.
4848
49−- `@extend-indented`:
49+- `@extend`:
5050Extend the range of this node to the end of the line and to lines that
5151are indented more than the line that this node starts on. This is useful
5252for languages like Python, where for the purpose of indentation some nodes
5353(like functions or classes) should also contain indented lines that follow them.
5454
55−- `@stop-extend`:
55+- `@extend.prevent-once`:
5656Prevents the first extension of an ancestor of this node. For example, in Python
5757a return expression always ends the block that it is in. Note that this only stops the
58−extension of the next `@extend-indented` capture. If multiple ancestors are captured,
58+extension of the next `@extend` capture. If multiple ancestors are captured,
5959only the extension of the innermost one is prevented. All other ancestors are unaffected
6060(regardless of whether the innermost ancestor would actually have been extended).
6161
helix-core/src/indent.rs+10−10
@@ -303,8 +303,8 @@ enum IndentScope {
303303/// A capture from the indent query which does not define an indent but extends
304304/// the range of a node. This is used before the indent is calculated.
305305enum ExtendCapture {
306− ExtendIndented,
307− StopExtend,
306+ Extend,
307+ PreventOnce,
308308}
309309
310310/// The result of running a tree-sitter indent query. This stores for
@@ -394,18 +394,18 @@ fn query_indents(
394394 let capture_type = match capture_name {
395395 "indent" => IndentCaptureType::Indent,
396396 "outdent" => IndentCaptureType::Outdent,
397− "extend-indented" => {
397+ "extend" => {
398398 extend_captures
399399 .entry(capture.node.id())
400400 .or_insert_with(|| Vec::with_capacity(1))
401− .push(ExtendCapture::ExtendIndented);
401+ .push(ExtendCapture::Extend);
402402 continue;
403403 }
404− "stop-extend" => {
404+ "extend.prevent-once" => {
405405 extend_captures
406406 .entry(capture.node.id())
407407 .or_insert_with(|| Vec::with_capacity(1))
408− .push(ExtendCapture::StopExtend);
408+ .push(ExtendCapture::PreventOnce);
409409 continue;
410410 }
411411 _ => {
@@ -478,10 +478,10 @@ fn extend_nodes<'a>(
478478 if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
479479 for capture in captures {
480480 match capture {
481− ExtendCapture::StopExtend => {
481+ ExtendCapture::PreventOnce => {
482482 stop_extend = true;
483483 }
484− ExtendCapture::ExtendIndented => {
484+ ExtendCapture::Extend => {
485485 node_captured = true;
486486 // We extend the node if
487487 // - the cursor is on the same line as the end of the node OR
@@ -574,8 +574,8 @@ pub fn treesitter_indent_for_pos(
574574 .descendant_for_byte_range(byte_pos, byte_pos)?;
575575 let (query_result, deepest_preceding) = {
576576 // The query range should intersect with all nodes directly preceding
577− // the cursor in case one of them is extended.
578− let mut deepest_preceding = None; // The deepest node preceding the cursor
577+ // the position of the indent query in case one of them is extended.
578+ let mut deepest_preceding = None; // The deepest node preceding the indent query position
579579 let mut tree_cursor = node.walk();
580580 for child in node.children(&mut tree_cursor) {
581581 if child.byte_range().end <= byte_pos {
runtime/queries/python/indents.scm+2−2
@@ -36,7 +36,7 @@
3636
3737 (function_definition)
3838 (class_definition)
39−] @extend-indented
39+] @extend
4040
4141[
4242 (return_statement)
@@ -44,7 +44,7 @@
4444 (continue_statement)
4545 (raise_statement)
4646 (pass_statement)
47−] @stop-extend
47+] @extend.prevent-once
4848
4949[
5050 ")"