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