diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-16 14:07:44 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-16 14:07:44 +0000 |
commit | 1adc3525873d2588987f2c29143536ce952d6ab2 (patch) | |
tree | ba86bbb6e4e82fb1a85ab6a830173c00f2415d5e /crates/ra_hir_expand/src/lib.rs | |
parent | 786cae520ad62c9a0a13f5ab18e5bd7e5b0c9825 (diff) | |
parent | 2eaa8c94a8a6b5cd86139c5e010ae95268b28658 (diff) |
Merge #2273
2273: goto in macro calls r=matklad a=matklad
![goto](https://user-images.githubusercontent.com/1711539/68984944-2a50ba80-0824-11ea-896c-c0ea8edcd0d6.gif)
This builds on the awesome infrastructure created by @edwin0cheng
Co-authored-by: Aleksey Kladov <[email protected]>
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 | ||