More correct expansion mapping

We can't really map arbitrary ranges, we only can map tokens
This commit is contained in:
Aleksey Kladov 2019-11-17 20:15:55 +03:00
parent c8f858d043
commit fd52d721e1
4 changed files with 74 additions and 44 deletions

View file

@ -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<TextUnit> {
pub fn map_token_down(
&self,
db: &impl HirDatabase,
token: Source<&SyntaxToken>,
) -> Option<Source<SyntaxToken>> {
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)
}
}