diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 37382d2df..8398c9ac7 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -77,14 +77,14 @@ pub fn token_tree_to_syntax_node( | |||
77 | } | 77 | } |
78 | 78 | ||
79 | impl TokenMap { | 79 | impl TokenMap { |
80 | pub fn token_by_offset(&self, relative_offset: TextUnit) -> Option<tt::TokenId> { | 80 | pub fn token_by_range(&self, relative_range: TextRange) -> Option<tt::TokenId> { |
81 | let (idx, _) = | 81 | let (idx, _) = |
82 | self.tokens.iter().enumerate().find(|(_, range)| range.contains(relative_offset))?; | 82 | self.tokens.iter().enumerate().find(|(_, range)| **range == relative_range)?; |
83 | Some(tt::TokenId(idx as u32)) | 83 | Some(tt::TokenId(idx as u32)) |
84 | } | 84 | } |
85 | 85 | ||
86 | pub fn relative_range_of(&self, tt: tt::TokenId) -> Option<TextRange> { | 86 | pub fn relative_range_of(&self, token_id: tt::TokenId) -> Option<TextRange> { |
87 | let idx = tt.0 as usize; | 87 | let idx = token_id.0 as usize; |
88 | self.tokens.get(idx).copied() | 88 | self.tokens.get(idx).copied() |
89 | } | 89 | } |
90 | 90 | ||
@@ -96,6 +96,11 @@ impl TokenMap { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | impl RevTokenMap { | 98 | impl RevTokenMap { |
99 | pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TextRange> { | ||
100 | let &(r, _) = self.ranges.iter().find(|(_, tid)| *tid == token_id)?; | ||
101 | Some(r) | ||
102 | } | ||
103 | |||
99 | fn add(&mut self, relative_range: TextRange, token_id: tt::TokenId) { | 104 | fn add(&mut self, relative_range: TextRange, token_id: tt::TokenId) { |
100 | self.ranges.push((relative_range, token_id.clone())) | 105 | self.ranges.push((relative_range, token_id.clone())) |
101 | } | 106 | } |