mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Add parent_expansion to HirFileId
This commit is contained in:
parent
159da285e9
commit
ae609d7953
1 changed files with 19 additions and 0 deletions
|
@ -20,6 +20,7 @@ use ra_syntax::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::ast_id_map::FileAstId;
|
use crate::ast_id_map::FileAstId;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Input to the analyzer is a set of files, where each file is identified by
|
/// Input to the analyzer is a set of files, where each file is identified by
|
||||||
/// `FileId` and contains source code. However, another source of source code in
|
/// `FileId` and contains source code. However, another source of source code in
|
||||||
|
@ -66,6 +67,24 @@ impl HirFileId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return expansion information if it is a macro-expansion file
|
||||||
|
pub fn parent_expansion(
|
||||||
|
self,
|
||||||
|
db: &dyn db::AstDatabase,
|
||||||
|
) -> Option<((HirFileId, HirFileId), Arc<ExpansionInfo>)> {
|
||||||
|
match self.0 {
|
||||||
|
HirFileIdRepr::FileId(_) => None,
|
||||||
|
HirFileIdRepr::MacroFile(macro_file) => {
|
||||||
|
let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
|
||||||
|
|
||||||
|
let def_file = loc.def.ast_id.file_id;
|
||||||
|
let arg_file = loc.ast_id.file_id;
|
||||||
|
|
||||||
|
db.macro_expansion_info(macro_file).map(|ex| ((arg_file, def_file), ex))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue