Support $crate in item and expr place.

This commit is contained in:
uHOOCCOOHu 2019-09-27 01:59:38 +08:00
parent 8cd23a4fb8
commit 2ecb126f5c
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
14 changed files with 268 additions and 37 deletions

View file

@ -58,6 +58,17 @@ impl HirFileId {
}
}
/// Get the crate which the macro lives in, if it is a macro file.
pub(crate) fn macro_crate(self, db: &impl AstDatabase) -> Option<Crate> {
match self.0 {
HirFileIdRepr::File(_) => None,
HirFileIdRepr::Macro(macro_file) => {
let loc = macro_file.macro_call_id.loc(db);
Some(loc.def.krate)
}
}
}
pub(crate) fn parse_or_expand_query(
db: &impl AstDatabase,
file_id: HirFileId,