fix: Fix multiple derives in one attribute not expanding all in expand_macro

This commit is contained in:
Lukas Wirth 2021-08-26 03:32:34 +02:00
parent 3f9f63c1bd
commit 0f3617f76f
6 changed files with 59 additions and 19 deletions

View file

@ -6,6 +6,7 @@
use either::Either;
use hir_expand::HirFileId;
use itertools::Itertools;
use syntax::ast::AttrsOwner;
use crate::{
@ -109,10 +110,13 @@ impl ChildBySource for ItemScope {
let item = ast_id.with_value(ast_id.to_node(db.upcast()));
res[keys::ATTR_MACRO].insert(item, call_id);
});
self.derive_macro_invocs().for_each(|(ast_id, (attr_id, call_id))| {
self.derive_macro_invocs().for_each(|(ast_id, calls)| {
let item = ast_id.to_node(db.upcast());
if let Some(attr) = item.attrs().nth(attr_id.ast_index as usize) {
res[keys::DERIVE_MACRO].insert(ast_id.with_value(attr), call_id);
let grouped = calls.iter().copied().into_group_map();
for (attr_id, calls) in grouped {
if let Some(attr) = item.attrs().nth(attr_id.ast_index as usize) {
res[keys::DERIVE_MACRO].insert(ast_id.with_value(attr), calls.into());
}
}
});