on master help sign in
Rename extend indent captures.
0813276Daniel Ebert
book/src/guides/indent.md+3−3
@@ -46,16 +46,16 @@ capture on the same line, the indent level isn't changed at all.
46- `@outdent` (default scope `all`):
46- `@outdent` (default scope `all`):
47Decrease the indent level by 1. The same rules as for `@indent` apply.
47Decrease the indent level by 1. The same rules as for `@indent` apply.
48
48
49−- `@extend-indented`:
49+- `@extend`:
50Extend the range of this node to the end of the line and to lines that
50Extend the range of this node to the end of the line and to lines that
51are indented more than the line that this node starts on. This is useful
51are indented more than the line that this node starts on. This is useful
52for languages like Python, where for the purpose of indentation some nodes
52for languages like Python, where for the purpose of indentation some nodes
53(like functions or classes) should also contain indented lines that follow them.
53(like functions or classes) should also contain indented lines that follow them.
54
54
55−- `@stop-extend`:
55+- `@extend.prevent-once`:
56Prevents the first extension of an ancestor of this node. For example, in Python
56Prevents the first extension of an ancestor of this node. For example, in Python
57a return expression always ends the block that it is in. Note that this only stops the
57a 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,
59only the extension of the innermost one is prevented. All other ancestors are unaffected
59only the extension of the innermost one is prevented. All other ancestors are unaffected
60(regardless of whether the innermost ancestor would actually have been extended).
60(regardless of whether the innermost ancestor would actually have been extended).
61
61
helix-core/src/indent.rs+10−10
@@ -303,8 +303,8 @@ enum IndentScope {
303/// A capture from the indent query which does not define an indent but extends
303/// A capture from the indent query which does not define an indent but extends
304/// the range of a node. This is used before the indent is calculated.
304/// the range of a node. This is used before the indent is calculated.
305enum ExtendCapture {
305enum ExtendCapture {
306− ExtendIndented,
306+ Extend,
307− StopExtend,
307+ PreventOnce,
308}
308}
309
309
310/// The result of running a tree-sitter indent query. This stores for
310/// The result of running a tree-sitter indent query. This stores for
@@ -394,18 +394,18 @@ fn query_indents(
394 let capture_type = match capture_name {
394 let capture_type = match capture_name {
395 "indent" => IndentCaptureType::Indent,
395 "indent" => IndentCaptureType::Indent,
396 "outdent" => IndentCaptureType::Outdent,
396 "outdent" => IndentCaptureType::Outdent,
397− "extend-indented" => {
397+ "extend" => {
398 extend_captures
398 extend_captures
399 .entry(capture.node.id())
399 .entry(capture.node.id())
400 .or_insert_with(|| Vec::with_capacity(1))
400 .or_insert_with(|| Vec::with_capacity(1))
401− .push(ExtendCapture::ExtendIndented);
401+ .push(ExtendCapture::Extend);
402 continue;
402 continue;
403 }
403 }
404− "stop-extend" => {
404+ "extend.prevent-once" => {
405 extend_captures
405 extend_captures
406 .entry(capture.node.id())
406 .entry(capture.node.id())
407 .or_insert_with(|| Vec::with_capacity(1))
407 .or_insert_with(|| Vec::with_capacity(1))
408− .push(ExtendCapture::StopExtend);
408+ .push(ExtendCapture::PreventOnce);
409 continue;
409 continue;
410 }
410 }
411 _ => {
411 _ => {
@@ -478,10 +478,10 @@ fn extend_nodes<'a>(
478 if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
478 if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
479 for capture in captures {
479 for capture in captures {
480 match capture {
480 match capture {
481− ExtendCapture::StopExtend => {
481+ ExtendCapture::PreventOnce => {
482 stop_extend = true;
482 stop_extend = true;
483 }
483 }
484− ExtendCapture::ExtendIndented => {
484+ ExtendCapture::Extend => {
485 node_captured = true;
485 node_captured = true;
486 // We extend the node if
486 // We extend the node if
487 // - the cursor is on the same line as the end of the node OR
487 // - the cursor is on the same line as the end of the node OR
@@ -574,8 +574,8 @@ pub fn treesitter_indent_for_pos(
574 .descendant_for_byte_range(byte_pos, byte_pos)?;
574 .descendant_for_byte_range(byte_pos, byte_pos)?;
575 let (query_result, deepest_preceding) = {
575 let (query_result, deepest_preceding) = {
576 // The query range should intersect with all nodes directly preceding
576 // The query range should intersect with all nodes directly preceding
577− // the cursor in case one of them is extended.
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 cursor
578+ let mut deepest_preceding = None; // The deepest node preceding the indent query position
579 let mut tree_cursor = node.walk();
579 let mut tree_cursor = node.walk();
580 for child in node.children(&mut tree_cursor) {
580 for child in node.children(&mut tree_cursor) {
581 if child.byte_range().end <= byte_pos {
581 if child.byte_range().end <= byte_pos {
runtime/queries/python/indents.scm+2−2
@@ -36,7 +36,7 @@
36
36
37 (function_definition)
37 (function_definition)
38 (class_definition)
38 (class_definition)
39−] @extend-indented
39+] @extend
40
40
41[
41[
42 (return_statement)
42 (return_statement)
@@ -44,7 +44,7 @@
44 (continue_statement)
44 (continue_statement)
45 (raise_statement)
45 (raise_statement)
46 (pass_statement)
46 (pass_statement)
47−] @stop-extend
47+] @extend.prevent-once
48
48
49[
49[
50 ")"
50 ")"