Fix precedence order of @align captures in indent computation (#8659)

precedence when multiple occur on the same line in an indent query.
pull/8661/head
Triton171 1 year ago committed by GitHub
parent f992c3b597
commit ef0c31db02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -271,7 +271,9 @@ impl Indentation {
} }
/// Add an indent capture to this indent. /// Add an indent capture to this indent.
/// All the captures that are added in this way should be on the same line. /// Only captures that apply to the same line should be added together in this way (otherwise use `add_line`)
/// and the captures should be added starting from the innermost tree-sitter node (currently this only matters
/// if multiple `@align` patterns occur on the same line).
fn add_capture(&mut self, added: IndentCaptureType) { fn add_capture(&mut self, added: IndentCaptureType) {
match added { match added {
IndentCaptureType::Indent => { IndentCaptureType::Indent => {
@ -295,10 +297,12 @@ impl Indentation {
self.outdent = 0; self.outdent = 0;
} }
IndentCaptureType::Align(align) => { IndentCaptureType::Align(align) => {
if self.align.is_none() {
self.align = Some(align); self.align = Some(align);
} }
} }
} }
}
fn into_string(self, indent_style: &IndentStyle) -> String { fn into_string(self, indent_style: &IndentStyle) -> String {
let indent = self.indent_always + self.indent; let indent = self.indent_always + self.indent;
let outdent = self.outdent_always + self.outdent; let outdent = self.outdent_always + self.outdent;

Loading…
Cancel
Save