|
|
@ -303,8 +303,8 @@ enum IndentScope {
|
|
|
|
/// A capture from the indent query which does not define an indent but extends
|
|
|
|
/// 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.
|
|
|
|
/// the range of a node. This is used before the indent is calculated.
|
|
|
|
enum ExtendCapture {
|
|
|
|
enum ExtendCapture {
|
|
|
|
ExtendIndented,
|
|
|
|
Extend,
|
|
|
|
StopExtend,
|
|
|
|
PreventOnce,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The result of running a tree-sitter indent query. This stores for
|
|
|
|
/// 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 {
|
|
|
|
let capture_type = match capture_name {
|
|
|
|
"indent" => IndentCaptureType::Indent,
|
|
|
|
"indent" => IndentCaptureType::Indent,
|
|
|
|
"outdent" => IndentCaptureType::Outdent,
|
|
|
|
"outdent" => IndentCaptureType::Outdent,
|
|
|
|
"extend-indented" => {
|
|
|
|
"extend" => {
|
|
|
|
extend_captures
|
|
|
|
extend_captures
|
|
|
|
.entry(capture.node.id())
|
|
|
|
.entry(capture.node.id())
|
|
|
|
.or_insert_with(|| Vec::with_capacity(1))
|
|
|
|
.or_insert_with(|| Vec::with_capacity(1))
|
|
|
|
.push(ExtendCapture::ExtendIndented);
|
|
|
|
.push(ExtendCapture::Extend);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"stop-extend" => {
|
|
|
|
"extend.prevent-once" => {
|
|
|
|
extend_captures
|
|
|
|
extend_captures
|
|
|
|
.entry(capture.node.id())
|
|
|
|
.entry(capture.node.id())
|
|
|
|
.or_insert_with(|| Vec::with_capacity(1))
|
|
|
|
.or_insert_with(|| Vec::with_capacity(1))
|
|
|
|
.push(ExtendCapture::StopExtend);
|
|
|
|
.push(ExtendCapture::PreventOnce);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
_ => {
|
|
|
@ -478,10 +478,10 @@ fn extend_nodes<'a>(
|
|
|
|
if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
|
|
|
|
if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
|
|
|
|
for capture in captures {
|
|
|
|
for capture in captures {
|
|
|
|
match capture {
|
|
|
|
match capture {
|
|
|
|
ExtendCapture::StopExtend => {
|
|
|
|
ExtendCapture::PreventOnce => {
|
|
|
|
stop_extend = true;
|
|
|
|
stop_extend = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ExtendCapture::ExtendIndented => {
|
|
|
|
ExtendCapture::Extend => {
|
|
|
|
node_captured = true;
|
|
|
|
node_captured = true;
|
|
|
|
// We extend the node if
|
|
|
|
// We extend the node if
|
|
|
|
// - the cursor is on the same line as the end of the node OR
|
|
|
|
// - 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)?;
|
|
|
|
.descendant_for_byte_range(byte_pos, byte_pos)?;
|
|
|
|
let (query_result, deepest_preceding) = {
|
|
|
|
let (query_result, deepest_preceding) = {
|
|
|
|
// The query range should intersect with all nodes directly preceding
|
|
|
|
// The query range should intersect with all nodes directly preceding
|
|
|
|
// the cursor in case one of them is extended.
|
|
|
|
// the position of the indent query in case one of them is extended.
|
|
|
|
let mut deepest_preceding = None; // The deepest node preceding the cursor
|
|
|
|
let mut deepest_preceding = None; // The deepest node preceding the indent query position
|
|
|
|
let mut tree_cursor = node.walk();
|
|
|
|
let mut tree_cursor = node.walk();
|
|
|
|
for child in node.children(&mut tree_cursor) {
|
|
|
|
for child in node.children(&mut tree_cursor) {
|
|
|
|
if child.byte_range().end <= byte_pos {
|
|
|
|
if child.byte_range().end <= byte_pos {
|
|
|
|