aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-09 09:49:35 +0000
committerAleksey Kladov <[email protected]>2019-11-09 09:49:35 +0000
commitf6c40c09e0b5afa1b341ab7675c815862e07d22a (patch)
tree72c427f5cf233cc7dc94f3f6bfc7eef178270edf /crates
parent561bb979cecd786f5d311ea7bddb1e15d77a3848 (diff)
Minor cleanup
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_expand/src/lib.rs14
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
152impl ExpansionInfo { 152impl 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