Fix AssistContext panic on sole whitespace selection

This commit is contained in:
Lukas Wirth 2021-10-12 21:29:08 +02:00
parent a871da3693
commit 086563f751

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 }
}