Fix AssistContext panic on sole whitespace selection
This commit is contained in:
parent
a871da3693
commit
086563f751
@ -77,9 +77,14 @@ pub(crate) fn new(
|
||||
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 }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user