From fd52d721e1ed9794048d63e546f43805d24d7ab8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 Nov 2019 20:15:55 +0300 Subject: More correct expansion mapping We can't really map arbitrary ranges, we only can map tokens --- crates/ra_hir/src/source_binder.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src/source_binder.rs') diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 75a467fb3..f0ed8e2b2 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -16,7 +16,7 @@ use ra_syntax::{ ast::{self, AstNode}, match_ast, AstPtr, SyntaxKind::*, - SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, + SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextUnit, }; use crate::{ @@ -131,11 +131,16 @@ pub struct Expansion { } impl Expansion { - pub fn translate_offset(&self, db: &impl HirDatabase, offset: TextUnit) -> Option { + pub fn map_token_down( + &self, + db: &impl HirDatabase, + token: Source<&SyntaxToken>, + ) -> Option> { let exp_info = self.file_id().expansion_info(db)?; - exp_info.translate_offset(offset) + exp_info.map_token_down(token) } - pub fn file_id(&self) -> HirFileId { + + fn file_id(&self) -> HirFileId { self.macro_call_id.as_file(MacroFileKind::Items) } } -- cgit v1.2.3