Skip to content

Commit 5251723

Browse files
Triton171pathwave
authored andcommitted
Rename extend indent captures.
Clarify comments in indent code.
1 parent ee7f1fd commit 5251723

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

book/src/guides/indent.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ capture on the same line, the indent level isn't changed at all.
4646
- `@outdent` (default scope `all`):
4747
Decrease the indent level by 1. The same rules as for `@indent` apply.
4848

49-
- `@extend-indented`:
49+
- `@extend`:
5050
Extend the range of this node to the end of the line and to lines that
5151
are indented more than the line that this node starts on. This is useful
5252
for 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`:
5656
Prevents the first extension of an ancestor of this node. For example, in Python
5757
a 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,
5959
only 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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
305305
enum 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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@
3636

3737
(function_definition)
3838
(class_definition)
39-
] @extend-indented
39+
] @extend
4040

4141
[
4242
(return_statement)
4343
(break_statement)
4444
(continue_statement)
4545
(raise_statement)
4646
(pass_statement)
47-
] @stop-extend
47+
] @extend.prevent-once
4848

4949
[
5050
")"

0 commit comments

Comments
 (0)