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_mbe/src/syntax_bridge.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'crates/ra_mbe/src/syntax_bridge.rs') diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 3f57ce3b5..37382d2df 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -77,6 +77,12 @@ pub fn token_tree_to_syntax_node( } impl TokenMap { + pub fn token_by_offset(&self, relative_offset: TextUnit) -> Option { + let (idx, _) = + self.tokens.iter().enumerate().find(|(_, range)| range.contains(relative_offset))?; + Some(tt::TokenId(idx as u32)) + } + pub fn relative_range_of(&self, tt: tt::TokenId) -> Option { let idx = tt.0 as usize; self.tokens.get(idx).copied() -- cgit v1.2.3