aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 3f57ce3b5..37382d2df 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -77,6 +77,12 @@ pub fn token_tree_to_syntax_node(
77} 77}
78 78
79impl TokenMap { 79impl TokenMap {
80 pub fn token_by_offset(&self, relative_offset: TextUnit) -> Option<tt::TokenId> {
81 let (idx, _) =
82 self.tokens.iter().enumerate().find(|(_, range)| range.contains(relative_offset))?;
83 Some(tt::TokenId(idx as u32))
84 }
85
80 pub fn relative_range_of(&self, tt: tt::TokenId) -> Option<TextRange> { 86 pub fn relative_range_of(&self, tt: tt::TokenId) -> Option<TextRange> {
81 let idx = tt.0 as usize; 87 let idx = tt.0 as usize;
82 self.tokens.get(idx).copied() 88 self.tokens.get(idx).copied()