diff options
author | Aleksey Kladov <[email protected]> | 2019-11-17 17:15:55 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-17 17:15:55 +0000 |
commit | fd52d721e1ed9794048d63e546f43805d24d7ab8 (patch) | |
tree | 4a57f22e985709c4206fb95fda04367a8e90b5a3 /crates/ra_hir | |
parent | c8f858d04323f93a4bacb143d92c976b2bc1e179 (diff) |
More correct expansion mapping
We can't really map arbitrary ranges, we only can map tokens
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 13 |
1 files changed, 9 insertions, 4 deletions
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::{ | |||
16 | ast::{self, AstNode}, | 16 | ast::{self, AstNode}, |
17 | match_ast, AstPtr, | 17 | match_ast, AstPtr, |
18 | SyntaxKind::*, | 18 | SyntaxKind::*, |
19 | SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, | 19 | SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextUnit, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | use crate::{ | 22 | use crate::{ |
@@ -131,11 +131,16 @@ pub struct Expansion { | |||
131 | } | 131 | } |
132 | 132 | ||
133 | impl Expansion { | 133 | impl Expansion { |
134 | pub fn translate_offset(&self, db: &impl HirDatabase, offset: TextUnit) -> Option<TextUnit> { | 134 | pub fn map_token_down( |
135 | &self, | ||
136 | db: &impl HirDatabase, | ||
137 | token: Source<&SyntaxToken>, | ||
138 | ) -> Option<Source<SyntaxToken>> { | ||
135 | let exp_info = self.file_id().expansion_info(db)?; | 139 | let exp_info = self.file_id().expansion_info(db)?; |
136 | exp_info.translate_offset(offset) | 140 | exp_info.map_token_down(token) |
137 | } | 141 | } |
138 | pub fn file_id(&self) -> HirFileId { | 142 | |
143 | fn file_id(&self) -> HirFileId { | ||
139 | self.macro_call_id.as_file(MacroFileKind::Items) | 144 | self.macro_call_id.as_file(MacroFileKind::Items) |
140 | } | 145 | } |
141 | } | 146 | } |