Allow name querying for derive helpers

This commit is contained in:
Lukas Wirth 2022-07-24 14:32:39 +02:00
parent aa1491ecde
commit ddad2847ab
8 changed files with 53 additions and 18 deletions

View file

@ -2255,12 +2255,27 @@ impl Local {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DeriveHelper {
pub(crate) derive: MacroId,
pub(crate) idx: usize,
}
impl DeriveHelper {
pub fn derive(&self) -> Macro {
Macro { id: self.derive.into() }
}
pub fn name(&self, db: &dyn HirDatabase) -> Name {
match self.derive {
MacroId::Macro2Id(_) => None,
MacroId::MacroRulesId(_) => None,
MacroId::ProcMacroId(proc_macro) => db
.proc_macro_data(proc_macro)
.helpers
.as_ref()
.and_then(|it| it.get(self.idx))
.cloned(),
}
.unwrap_or_else(|| Name::missing())
}
}
// FIXME: Wrong name? This is could also be a registered attribute