10533: fix: Fix AssistContext panic on sole whitespace selection r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-10-12 19:29:47 +00:00 committed by GitHub
commit 137ac67f5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,9 +77,14 @@ impl<'a> AssistContext<'a> {
left.right_biased().and_then(|t| algo::skip_whitespace_token(t, Direction::Next));
let right =
right.left_biased().and_then(|t| algo::skip_whitespace_token(t, Direction::Prev));
let left = left.map(|t| t.text_range().start()).unwrap_or(start).clamp(start, end);
let right = right.map(|t| t.text_range().end()).unwrap_or(end).clamp(start, end);
let trimmed_range = TextRange::new(left, right);
let left = left.map(|t| t.text_range().start().clamp(start, end));
let right = right.map(|t| t.text_range().end().clamp(start, end));
let trimmed_range = match (left, right) {
(Some(left), Some(right)) if left <= right => TextRange::new(left, right),
// Selection solely consists of whitespace so just fall back to the original
_ => frange.range,
};
AssistContext { config, sema, frange, source_file, trimmed_range }
}