mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Complete derive helper attributes
Only their names, anything can go inside.
This commit is contained in:
parent
e6276c8b64
commit
890d155ffe
5 changed files with 111 additions and 4 deletions
|
@ -510,6 +510,22 @@ impl<'db> SemanticsImpl<'db> {
|
|||
self.with_ctx(|ctx| ctx.has_derives(adt))
|
||||
}
|
||||
|
||||
pub fn derive_helpers_in_scope(&self, adt: &ast::Adt) -> Option<Vec<(Symbol, Symbol)>> {
|
||||
let sa = self.analyze_no_infer(adt.syntax())?;
|
||||
let id = self.db.ast_id_map(sa.file_id).ast_id(adt);
|
||||
let result = sa
|
||||
.resolver
|
||||
.def_map()
|
||||
.derive_helpers_in_scope(InFile::new(sa.file_id, id))?
|
||||
.iter()
|
||||
.map(|(name, macro_, _)| {
|
||||
let macro_name = Macro::from(*macro_).name(self.db).symbol().clone();
|
||||
(name.symbol().clone(), macro_name)
|
||||
})
|
||||
.collect();
|
||||
Some(result)
|
||||
}
|
||||
|
||||
pub fn derive_helper(&self, attr: &ast::Attr) -> Option<Vec<(Macro, MacroFileId)>> {
|
||||
let adt = attr.syntax().ancestors().find_map(ast::Item::cast).and_then(|it| match it {
|
||||
ast::Item::Struct(it) => Some(ast::Adt::Struct(it)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue