|
|
|
@ -461,14 +461,14 @@ fn query_indents(
|
|
|
|
|
/// so that the indent computation starts with the correct syntax node.
|
|
|
|
|
fn extend_nodes<'a>(
|
|
|
|
|
node: &mut Node<'a>,
|
|
|
|
|
deepest_preceding: Option<Node<'a>>,
|
|
|
|
|
mut deepest_preceding: Node<'a>,
|
|
|
|
|
extend_captures: &HashMap<usize, Vec<ExtendCapture>>,
|
|
|
|
|
text: RopeSlice,
|
|
|
|
|
line: usize,
|
|
|
|
|
tab_width: usize,
|
|
|
|
|
) {
|
|
|
|
|
if let Some(mut deepest_preceding) = deepest_preceding {
|
|
|
|
|
let mut stop_extend = false;
|
|
|
|
|
|
|
|
|
|
while deepest_preceding != *node {
|
|
|
|
|
let mut extend_node = false;
|
|
|
|
|
// This will be set to true if this node is captured, regardless of whether
|
|
|
|
@ -490,8 +490,7 @@ fn extend_nodes<'a>(
|
|
|
|
|
if deepest_preceding.end_position().row == line {
|
|
|
|
|
extend_node = true;
|
|
|
|
|
} else {
|
|
|
|
|
let cursor_indent =
|
|
|
|
|
indent_level_for_line(text.line(line), tab_width);
|
|
|
|
|
let cursor_indent = indent_level_for_line(text.line(line), tab_width);
|
|
|
|
|
let node_indent = indent_level_for_line(
|
|
|
|
|
text.line(deepest_preceding.start_position().row),
|
|
|
|
|
tab_width,
|
|
|
|
@ -515,7 +514,6 @@ fn extend_nodes<'a>(
|
|
|
|
|
// This parent always exists since node is an ancestor of deepest_preceding
|
|
|
|
|
deepest_preceding = deepest_preceding.parent().unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Use the syntax tree to determine the indentation for a given position.
|
|
|
|
@ -612,6 +610,7 @@ pub fn treesitter_indent_for_pos(
|
|
|
|
|
let extend_captures = query_result.extend_captures;
|
|
|
|
|
|
|
|
|
|
// Check for extend captures, potentially changing the node that the indent calculation starts with
|
|
|
|
|
if let Some(deepest_preceding) = deepest_preceding {
|
|
|
|
|
extend_nodes(
|
|
|
|
|
&mut node,
|
|
|
|
|
deepest_preceding,
|
|
|
|
@ -620,6 +619,7 @@ pub fn treesitter_indent_for_pos(
|
|
|
|
|
line,
|
|
|
|
|
tab_width,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
let mut first_in_line = get_first_in_line(node, new_line.then(|| byte_pos));
|
|
|
|
|
|
|
|
|
|
let mut result = Indentation::default();
|
|
|
|
|