diff options
Diffstat (limited to 'crates/libsyntax2/src/yellow/syntax_text.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax_text.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/yellow/syntax_text.rs b/crates/libsyntax2/src/yellow/syntax_text.rs index b855687c4..280bedd78 100644 --- a/crates/libsyntax2/src/yellow/syntax_text.rs +++ b/crates/libsyntax2/src/yellow/syntax_text.rs | |||
@@ -61,6 +61,18 @@ impl<'a> SyntaxText<'a> { | |||
61 | }); | 61 | }); |
62 | SyntaxText { node: self.node, range } | 62 | SyntaxText { node: self.node, range } |
63 | } | 63 | } |
64 | pub fn char_at(&self, offset: TextUnit) -> Option<char> { | ||
65 | let mut start: TextUnit = 0.into(); | ||
66 | for chunk in self.chunks() { | ||
67 | let end = start + TextUnit::of_str(chunk); | ||
68 | if start <= offset && offset < end { | ||
69 | let off: usize = u32::from(offset - start) as usize; | ||
70 | return Some(chunk[off..].chars().next().unwrap()); | ||
71 | } | ||
72 | start = end; | ||
73 | } | ||
74 | None | ||
75 | } | ||
64 | } | 76 | } |
65 | 77 | ||
66 | impl<'a> fmt::Debug for SyntaxText<'a> { | 78 | impl<'a> fmt::Debug for SyntaxText<'a> { |