mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Merge #11455
11455: Handle proc-macro functions as the proc-macro they resolve to r=Veykril a=Veykril Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11212 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
979b5b32bc
7 changed files with 89 additions and 9 deletions
|
@ -1376,6 +1376,23 @@ impl Function {
|
|||
db.function_data(self.id).has_body()
|
||||
}
|
||||
|
||||
pub fn as_proc_macro(self, db: &dyn HirDatabase) -> Option<MacroDef> {
|
||||
let function_data = db.function_data(self.id);
|
||||
let attrs = &function_data.attrs;
|
||||
if !(attrs.is_proc_macro()
|
||||
|| attrs.is_proc_macro_attribute()
|
||||
|| attrs.is_proc_macro_derive())
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let loc = self.id.lookup(db.upcast());
|
||||
let krate = loc.krate(db);
|
||||
let def_map = db.crate_def_map(krate.into());
|
||||
let name = &function_data.name;
|
||||
let mut exported_proc_macros = def_map.exported_proc_macros();
|
||||
exported_proc_macros.find(|(_, mac_name)| mac_name == name).map(|(id, _)| MacroDef { id })
|
||||
}
|
||||
|
||||
/// A textual representation of the HIR of this function for debugging purposes.
|
||||
pub fn debug_hir(self, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(self.id.into());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue