diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index ca32c8b1fb..7fe62d7cd8 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -1627,9 +1627,7 @@ impl BufferSnapshot { &self, row_range: Range, ) -> Option> + '_> { - let language = self.language.as_ref()?; - let grammar = language.grammar.as_ref()?; - let config = &language.config; + let config = &self.language.as_ref()?.config; let prev_non_blank_row = self.prev_non_blank_row(row_range.start); // Find the suggested indentation ranges based on the syntax tree. @@ -1639,20 +1637,24 @@ impl BufferSnapshot { let mut matches = self.syntax.matches(range, &self.text, |grammar| { Some(&grammar.indents_config.as_ref()?.query) }); + let indent_configs = matches + .grammars() + .iter() + .map(|grammar| grammar.indents_config.as_ref().unwrap()) + .collect::>(); let mut indent_ranges = Vec::>::new(); while let Some(mat) = matches.peek() { let mut start: Option = None; let mut end: Option = None; - if let Some(config) = &grammar.indents_config { - for capture in mat.captures { - if capture.index == config.indent_capture_ix { - start.get_or_insert(Point::from_ts_point(capture.node.start_position())); - end.get_or_insert(Point::from_ts_point(capture.node.end_position())); - } else if Some(capture.index) == config.end_capture_ix { - end = Some(Point::from_ts_point(capture.node.start_position())); - } + let config = &indent_configs[mat.grammar_index]; + for capture in mat.captures { + if capture.index == config.indent_capture_ix { + start.get_or_insert(Point::from_ts_point(capture.node.start_position())); + end.get_or_insert(Point::from_ts_point(capture.node.end_position())); + } else if Some(capture.index) == config.end_capture_ix { + end = Some(Point::from_ts_point(capture.node.start_position())); } } diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 8a912b9a9b..f2a33ccbd3 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -998,6 +998,7 @@ fn test_autoindent_language_without_indents_query(cx: &mut MutableAppContext) { Arc::new(Language::new( LanguageConfig { name: "Markdown".into(), + auto_indent_using_last_non_empty_line: false, ..Default::default() }, Some(tree_sitter_json::language()),