From 081327695f7d4740f8a66bf2da75905656f70a58 Mon Sep 17 00:00:00 2001 From: Daniel Ebert Date: Sat, 8 Oct 2022 11:04:11 +0200 Subject: [PATCH] Rename extend indent captures. Clarify comments in indent code. --- book/src/guides/indent.md | 6 +++--- helix-core/src/indent.rs | 20 ++++++++++---------- runtime/queries/python/indents.scm | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/book/src/guides/indent.md b/book/src/guides/indent.md index 13550846f..0e2592897 100644 --- a/book/src/guides/indent.md +++ b/book/src/guides/indent.md @@ -46,16 +46,16 @@ capture on the same line, the indent level isn't changed at all. - `@outdent` (default scope `all`): Decrease the indent level by 1. The same rules as for `@indent` apply. -- `@extend-indented`: +- `@extend`: Extend the range of this node to the end of the line and to lines that are indented more than the line that this node starts on. This is useful for languages like Python, where for the purpose of indentation some nodes (like functions or classes) should also contain indented lines that follow them. -- `@stop-extend`: +- `@extend.prevent-once`: Prevents the first extension of an ancestor of this node. For example, in Python a return expression always ends the block that it is in. Note that this only stops the -extension of the next `@extend-indented` capture. If multiple ancestors are captured, +extension of the next `@extend` capture. If multiple ancestors are captured, only the extension of the innermost one is prevented. All other ancestors are unaffected (regardless of whether the innermost ancestor would actually have been extended). diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index 1ea8f18b8..9526fc8ad 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -303,8 +303,8 @@ enum IndentScope { /// A capture from the indent query which does not define an indent but extends /// the range of a node. This is used before the indent is calculated. enum ExtendCapture { - ExtendIndented, - StopExtend, + Extend, + PreventOnce, } /// The result of running a tree-sitter indent query. This stores for @@ -394,18 +394,18 @@ fn query_indents( let capture_type = match capture_name { "indent" => IndentCaptureType::Indent, "outdent" => IndentCaptureType::Outdent, - "extend-indented" => { + "extend" => { extend_captures .entry(capture.node.id()) .or_insert_with(|| Vec::with_capacity(1)) - .push(ExtendCapture::ExtendIndented); + .push(ExtendCapture::Extend); continue; } - "stop-extend" => { + "extend.prevent-once" => { extend_captures .entry(capture.node.id()) .or_insert_with(|| Vec::with_capacity(1)) - .push(ExtendCapture::StopExtend); + .push(ExtendCapture::PreventOnce); continue; } _ => { @@ -478,10 +478,10 @@ fn extend_nodes<'a>( if let Some(captures) = extend_captures.get(&deepest_preceding.id()) { for capture in captures { match capture { - ExtendCapture::StopExtend => { + ExtendCapture::PreventOnce => { stop_extend = true; } - ExtendCapture::ExtendIndented => { + ExtendCapture::Extend => { node_captured = true; // We extend the node if // - the cursor is on the same line as the end of the node OR @@ -574,8 +574,8 @@ pub fn treesitter_indent_for_pos( .descendant_for_byte_range(byte_pos, byte_pos)?; let (query_result, deepest_preceding) = { // The query range should intersect with all nodes directly preceding - // the cursor in case one of them is extended. - let mut deepest_preceding = None; // The deepest node preceding the cursor + // the position of the indent query in case one of them is extended. + let mut deepest_preceding = None; // The deepest node preceding the indent query position let mut tree_cursor = node.walk(); for child in node.children(&mut tree_cursor) { if child.byte_range().end <= byte_pos { diff --git a/runtime/queries/python/indents.scm b/runtime/queries/python/indents.scm index c648aebc0..b7b499c07 100644 --- a/runtime/queries/python/indents.scm +++ b/runtime/queries/python/indents.scm @@ -36,7 +36,7 @@ (function_definition) (class_definition) -] @extend-indented +] @extend [ (return_statement) @@ -44,7 +44,7 @@ (continue_statement) (raise_statement) (pass_statement) -] @stop-extend +] @extend.prevent-once [ ")"