diff options
Diffstat (limited to 'crates/ra_mbe/src/syntax_bridge.rs')
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 8398c9ac7..fe3b70b8d 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -20,7 +20,7 @@ pub struct TokenMap { | |||
20 | /// Maps relative range of the expanded syntax node to `tt::TokenId` | 20 | /// Maps relative range of the expanded syntax node to `tt::TokenId` |
21 | #[derive(Debug, PartialEq, Eq, Default)] | 21 | #[derive(Debug, PartialEq, Eq, Default)] |
22 | pub struct RevTokenMap { | 22 | pub struct RevTokenMap { |
23 | pub ranges: Vec<(TextRange, tt::TokenId)>, | 23 | ranges: Vec<(TextRange, tt::TokenId)>, |
24 | } | 24 | } |
25 | 25 | ||
26 | /// Convert the syntax tree (what user has written) to a `TokenTree` (what macro | 26 | /// Convert the syntax tree (what user has written) to a `TokenTree` (what macro |
@@ -96,6 +96,10 @@ impl TokenMap { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | impl RevTokenMap { | 98 | impl RevTokenMap { |
99 | pub fn token_by_range(&self, relative_range: TextRange) -> Option<tt::TokenId> { | ||
100 | self.ranges.iter().find(|&it| it.0 == relative_range).map(|it| it.1) | ||
101 | } | ||
102 | |||
99 | pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TextRange> { | 103 | pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TextRange> { |
100 | let &(r, _) = self.ranges.iter().find(|(_, tid)| *tid == token_id)?; | 104 | let &(r, _) = self.ranges.iter().find(|(_, tid)| *tid == token_id)?; |
101 | Some(r) | 105 | Some(r) |