Skip to content

Commit 086563f

Browse files
committed
Fix AssistContext panic on sole whitespace selection
1 parent a871da3 commit 086563f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/ide_assists/src/assist_context.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ impl<'a> AssistContext<'a> {
7777
left.right_biased().and_then(|t| algo::skip_whitespace_token(t, Direction::Next));
7878
let right =
7979
right.left_biased().and_then(|t| algo::skip_whitespace_token(t, Direction::Prev));
80-
let left = left.map(|t| t.text_range().start()).unwrap_or(start).clamp(start, end);
81-
let right = right.map(|t| t.text_range().end()).unwrap_or(end).clamp(start, end);
82-
let trimmed_range = TextRange::new(left, right);
80+
let left = left.map(|t| t.text_range().start().clamp(start, end));
81+
let right = right.map(|t| t.text_range().end().clamp(start, end));
82+
83+
let trimmed_range = match (left, right) {
84+
(Some(left), Some(right)) if left <= right => TextRange::new(left, right),
85+
// Selection solely consists of whitespace so just fall back to the original
86+
_ => frange.range,
87+
};
8388

8489
AssistContext { config, sema, frange, source_file, trimmed_range }
8590
}

0 commit comments

Comments
 (0)