diff options
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 26531cb05..6bfbb2f79 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -160,6 +160,15 @@ pub struct ExpansionInfo { | |||
160 | } | 160 | } |
161 | 161 | ||
162 | impl ExpansionInfo { | 162 | impl ExpansionInfo { |
163 | pub fn translate_offset(&self, offset: TextUnit) -> Option<TextUnit> { | ||
164 | let offset = offset.checked_sub(self.arg_start.1)?; | ||
165 | let token_id = self.macro_arg.1.token_by_offset(offset)?; | ||
166 | let token_id = tt::TokenId(token_id.0 + self.shift); | ||
167 | |||
168 | let (r, _) = self.exp_map.ranges.iter().find(|(_, tid)| *tid == token_id)?; | ||
169 | Some(r.start()) | ||
170 | } | ||
171 | |||
163 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { | 172 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { |
164 | let token_id = look_in_rev_map(&self.exp_map, from)?; | 173 | let token_id = look_in_rev_map(&self.exp_map, from)?; |
165 | 174 | ||