pub fn token_at_cursor<'a>(
spans: impl Iterator<Item = &'a Range<usize>> + Clone,
source: &str,
offset: usize,
) -> Option<Range<usize>>Expand description
The token a cursor at byte offset belongs to, given the tokens’ spans.
A cursor sits between characters, so for ex:fo|; it belongs to ex:fo
(the word being typed), and for |ex:name to ex:name. In order:
- a word token that contains the cursor,
- a word token that ends at the cursor,
- a punctuation token that contains the cursor or ends at it,
- none: the cursor is in whitespace.