From 2eaa8c94a8a6b5cd86139c5e010ae95268b28658 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 16 Nov 2019 16:49:26 +0300 Subject: Goto definition works inside macros --- crates/ra_hir_expand/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_hir_expand') 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 { } impl ExpansionInfo { + pub fn translate_offset(&self, offset: TextUnit) -> Option { + let offset = offset.checked_sub(self.arg_start.1)?; + let token_id = self.macro_arg.1.token_by_offset(offset)?; + let token_id = tt::TokenId(token_id.0 + self.shift); + + let (r, _) = self.exp_map.ranges.iter().find(|(_, tid)| *tid == token_id)?; + Some(r.start()) + } + pub fn find_range(&self, from: TextRange) -> Option<(HirFileId, TextRange)> { let token_id = look_in_rev_map(&self.exp_map, from)?; -- cgit v1.2.3