mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
More correct expansion mapping
We can't really map arbitrary ranges, we only can map tokens
This commit is contained in:
parent
c8f858d043
commit
fd52d721e1
4 changed files with 74 additions and 44 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue