mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Add macro_expansion_info in hir_expand
This commit is contained in:
parent
9fd546bec2
commit
159da285e9
5 changed files with 212 additions and 47 deletions
|
@ -16,7 +16,7 @@ use std::hash::{Hash, Hasher};
|
|||
use ra_db::{salsa, CrateId, FileId};
|
||||
use ra_syntax::{
|
||||
ast::{self, AstNode},
|
||||
SyntaxNode,
|
||||
SyntaxNode, TextRange,
|
||||
};
|
||||
|
||||
use crate::ast_id_map::FileAstId;
|
||||
|
@ -112,6 +112,39 @@ impl MacroCallId {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
/// ExpansionInfo mainly describle how to map text range between src and expaned macro
|
||||
pub struct ExpansionInfo {
|
||||
pub arg_map: Vec<(TextRange, TextRange)>,
|
||||
pub def_map: Vec<(TextRange, TextRange)>,
|
||||
}
|
||||
|
||||
impl ExpansionInfo {
|
||||
pub fn find_range(
|
||||
&self,
|
||||
from: TextRange,
|
||||
(arg_file_id, def_file_id): (HirFileId, HirFileId),
|
||||
) -> Option<(HirFileId, TextRange)> {
|
||||
for (src, dest) in &self.arg_map {
|
||||
dbg!((src, *dest, "arg_map"));
|
||||
if src.is_subrange(&from) {
|
||||
dbg!((arg_file_id, *dest));
|
||||
return Some((arg_file_id, *dest));
|
||||
}
|
||||
}
|
||||
|
||||
for (src, dest) in &self.def_map {
|
||||
dbg!((src, *dest, "def_map"));
|
||||
if src.is_subrange(&from) {
|
||||
dbg!((arg_file_id, *dest));
|
||||
return Some((def_file_id, *dest));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// `AstId` points to an AST node in any file.
|
||||
///
|
||||
/// It is stable across reparses, and can be used as salsa key/value.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue