diff options
Diffstat (limited to 'crates/ra_hir_expand/src')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index b219b8fbf..151d1d785 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -151,19 +151,21 @@ pub struct ExpansionInfo { | |||
151 | 151 | ||
152 | impl ExpansionInfo { | 152 | impl ExpansionInfo { |
153 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { | 153 | pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { |
154 | fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option<tt::TokenId> { | ||
155 | exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) | ||
156 | } | ||
157 | |||
158 | let token_id = look_in_rev_map(&self.exp_map, from)?; | 154 | let token_id = look_in_rev_map(&self.exp_map, from)?; |
159 | let (token_map, file_offset, token_id) = if token_id.0 >= self.shift { | 155 | |
156 | let (token_map, (file_id, start_offset), token_id) = if token_id.0 >= self.shift { | ||
160 | (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) | 157 | (&self.macro_arg.1, self.arg_start, tt::TokenId(token_id.0 - self.shift).into()) |
161 | } else { | 158 | } else { |
162 | (&self.macro_def.1, self.def_start, token_id) | 159 | (&self.macro_def.1, self.def_start, token_id) |
163 | }; | 160 | }; |
164 | 161 | ||
165 | let range = token_map.relative_range_of(token_id)?; | 162 | let range = token_map.relative_range_of(token_id)?; |
166 | Some((file_offset.0, TextRange::offset_len(range.start() + file_offset.1, range.len()))) | 163 | |
164 | return Some((file_id, range + start_offset)); | ||
165 | |||
166 | fn look_in_rev_map(exp_map: &mbe::RevTokenMap, from: TextRange) -> Option<tt::TokenId> { | ||
167 | exp_map.ranges.iter().find(|&it| it.0.is_subrange(&from)).map(|it| it.1) | ||
168 | } | ||
167 | } | 169 | } |
168 | } | 170 | } |
169 | 171 | ||