|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|
|
|
|
chars::{char_is_line_ending, char_is_whitespace},
|
|
|
|
|
find_first_non_whitespace_char,
|
|
|
|
|
graphemes::{grapheme_width, tab_width_at},
|
|
|
|
|
syntax::{LanguageConfiguration, RopeProvider, Syntax},
|
|
|
|
|
syntax::{IndentationHeuristic, LanguageConfiguration, RopeProvider, Syntax},
|
|
|
|
|
tree_sitter::Node,
|
|
|
|
|
Rope, RopeGraphemes, RopeSlice,
|
|
|
|
|
};
|
|
|
|
@ -931,6 +931,7 @@ pub fn treesitter_indent_for_pos<'a>(
|
|
|
|
|
pub fn indent_for_newline(
|
|
|
|
|
language_config: Option<&LanguageConfiguration>,
|
|
|
|
|
syntax: Option<&Syntax>,
|
|
|
|
|
indent_heuristic: &IndentationHeuristic,
|
|
|
|
|
indent_style: &IndentStyle,
|
|
|
|
|
tab_width: usize,
|
|
|
|
|
text: RopeSlice,
|
|
|
|
@ -939,7 +940,12 @@ pub fn indent_for_newline(
|
|
|
|
|
current_line: usize,
|
|
|
|
|
) -> String {
|
|
|
|
|
let indent_width = indent_style.indent_width(tab_width);
|
|
|
|
|
if let (Some(query), Some(syntax)) = (
|
|
|
|
|
if let (
|
|
|
|
|
IndentationHeuristic::TreeSitter | IndentationHeuristic::Hybrid,
|
|
|
|
|
Some(query),
|
|
|
|
|
Some(syntax),
|
|
|
|
|
) = (
|
|
|
|
|
indent_heuristic,
|
|
|
|
|
language_config.and_then(|config| config.indent_query()),
|
|
|
|
|
syntax,
|
|
|
|
|
) {
|
|
|
|
@ -953,6 +959,7 @@ pub fn indent_for_newline(
|
|
|
|
|
line_before_end_pos,
|
|
|
|
|
true,
|
|
|
|
|
) {
|
|
|
|
|
if let IndentationHeuristic::Hybrid = indent_heuristic {
|
|
|
|
|
// We want to compute the indentation not only based on the
|
|
|
|
|
// syntax tree but also on the actual indentation of a previous
|
|
|
|
|
// line. This makes indentation computation more resilient to
|
|
|
|
@ -998,6 +1005,7 @@ pub fn indent_for_newline(
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return indent.to_string(indent_style, tab_width);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|