Fix crash when querying for enclosing brackets at EOF

This commit is contained in:
Max Brunsfeld 2022-09-02 10:23:46 -07:00
parent 0588360bf0
commit 0777af1dd3
2 changed files with 11 additions and 1 deletions

View file

@ -2059,7 +2059,8 @@ impl BufferSnapshot {
range: Range<T>,
) -> Option<(Range<usize>, Range<usize>)> {
// Find bracket pairs that *inclusively* contain the given range.
let range = range.start.to_offset(self).saturating_sub(1)..range.end.to_offset(self) + 1;
let range = range.start.to_offset(self).saturating_sub(1)
..self.len().min(range.end.to_offset(self) + 1);
let mut matches = self.syntax.matches(range, &self.text, |grammar| {
grammar.brackets_config.as_ref().map(|c| &c.query)
});