mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
use the included file as the source of expanded include macro
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
This commit is contained in:
parent
a0ed87ff56
commit
3bb9efb6b7
5 changed files with 107 additions and 28 deletions
|
@ -84,7 +84,11 @@ impl HirFileId {
|
|||
}
|
||||
MacroCallId::EagerMacro(id) => {
|
||||
let loc = db.lookup_intern_eager_expansion(id);
|
||||
loc.call.file_id
|
||||
if let Some(included_file) = loc.included_file {
|
||||
return included_file;
|
||||
} else {
|
||||
loc.call.file_id
|
||||
}
|
||||
}
|
||||
};
|
||||
file_id.original_file(db)
|
||||
|
@ -188,6 +192,21 @@ impl HirFileId {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Return whether this file is an include macro
|
||||
pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
|
||||
match self.0 {
|
||||
HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id {
|
||||
MacroCallId::EagerMacro(id) => {
|
||||
let loc = db.lookup_intern_eager_expansion(id);
|
||||
return loc.included_file.is_some();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -315,6 +334,8 @@ pub struct EagerCallLoc {
|
|||
pub(crate) subtree: Arc<tt::Subtree>,
|
||||
pub(crate) krate: CrateId,
|
||||
pub(crate) call: AstId<ast::MacroCall>,
|
||||
// The included file ID of the include macro.
|
||||
pub(crate) included_file: Option<FileId>,
|
||||
}
|
||||
|
||||
/// ExpansionInfo mainly describes how to map text range between src and expanded macro
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue