Allow auto-indenting with syntax errors when using regex-based indent matches to improve bash auto-indent behavior (#24160)

- Fixes auto-indent issues around `elif` caused by auto-indent being prevented due to syntax errors generated before `elif` clause completed

Release Notes:

- Fixed an issue where inserting an elif before an else in bash would
not properly auto-indent

---------

Co-authored-by: Conrad Irwin <conrad@zed.dev>
This commit is contained in:
Ben Kunkle 2025-02-03 21:34:37 -06:00 committed by GitHub
parent 66d0cdfd91
commit 8742c18107
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 53 additions and 8 deletions

View file

@ -2897,12 +2897,19 @@ impl BufferSnapshot {
let mut indent_from_prev_row = false;
let mut outdent_from_prev_row = false;
let mut outdent_to_row = u32::MAX;
let mut from_regex = false;
while let Some((indent_row, delta)) = indent_changes.peek() {
match indent_row.cmp(&row) {
Ordering::Equal => match delta {
Ordering::Less => outdent_from_prev_row = true,
Ordering::Greater => indent_from_prev_row = true,
Ordering::Less => {
from_regex = true;
outdent_from_prev_row = true
}
Ordering::Greater => {
indent_from_prev_row = true;
from_regex = true
}
_ => {}
},
@ -2935,32 +2942,32 @@ impl BufferSnapshot {
Some(IndentSuggestion {
basis_row: prev_row,
delta: Ordering::Equal,
within_error,
within_error: within_error && !from_regex,
})
} else if indent_from_prev_row {
Some(IndentSuggestion {
basis_row: prev_row,
delta: Ordering::Greater,
within_error,
within_error: within_error && !from_regex,
})
} else if outdent_to_row < prev_row {
Some(IndentSuggestion {
basis_row: outdent_to_row,
delta: Ordering::Equal,
within_error,
within_error: within_error && !from_regex,
})
} else if outdent_from_prev_row {
Some(IndentSuggestion {
basis_row: prev_row,
delta: Ordering::Less,
within_error,
within_error: within_error && !from_regex,
})
} else if config.auto_indent_using_last_non_empty_line || !self.is_line_blank(prev_row)
{
Some(IndentSuggestion {
basis_row: prev_row,
delta: Ordering::Equal,
within_error,
within_error: within_error && !from_regex,
})
} else {
None