diff --git a/crates/ide-completion/src/completions/attribute/derive.rs b/crates/ide-completion/src/completions/attribute/derive.rs index 0d4a292e0f7..3aaaecd4746 100644 --- a/crates/ide-completion/src/completions/attribute/derive.rs +++ b/crates/ide-completion/src/completions/attribute/derive.rs @@ -11,8 +11,10 @@ }; pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) { - let qualified = match ctx.path_context() { - Some(&PathCompletionCtx { kind: PathKind::Derive, ref qualified, .. }) => qualified, + let (qualified, existing_derives) = match ctx.path_context() { + Some(PathCompletionCtx { + kind: PathKind::Derive { existing_derives }, qualified, .. + }) => (qualified, existing_derives), _ => return, }; @@ -32,7 +34,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) { for (name, def) in module.scope(ctx.db, Some(ctx.module)) { let add_def = match def { ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => { - !ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db) + !existing_derives.contains(&mac) && mac.is_derive(ctx.db) } ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true, _ => false, @@ -48,7 +50,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) { ctx.process_all_names(&mut |name, def| { let mac = match def { ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) - if !ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db) => + if !existing_derives.contains(&mac) && mac.is_derive(ctx.db) => { mac } @@ -74,7 +76,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) { let mut components = vec![derive_completion.label]; components.extend(derive_completion.dependencies.iter().filter( |&&dependency| { - !ctx.existing_derives + !existing_derives .iter() .map(|it| it.name(ctx.db)) .any(|it| it.to_smol_str() == dependency) diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index 6266bcef34e..33ae365cff7 100644 --- a/crates/ide-completion/src/completions/flyimport.rs +++ b/crates/ide-completion/src/completions/flyimport.rs @@ -120,7 +120,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) kind @ (PathKind::Expr { .. } | PathKind::Type { .. } | PathKind::Attr { .. } - | PathKind::Derive + | PathKind::Derive { .. } | PathKind::Pat), .. })), @@ -188,10 +188,10 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) (PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db), (PathKind::Attr { .. }, _) => false, - (PathKind::Derive, ItemInNs::Macros(mac)) => { - mac.is_derive(ctx.db) && !ctx.existing_derives.contains(&mac) + (PathKind::Derive { existing_derives }, ItemInNs::Macros(mac)) => { + mac.is_derive(ctx.db) && !existing_derives.contains(&mac) } - (PathKind::Derive, _) => false, + (PathKind::Derive { .. }, _) => false, } }; diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs index 4ed083a5245..781dcfd403d 100644 --- a/crates/ide-completion/src/context.rs +++ b/crates/ide-completion/src/context.rs @@ -101,7 +101,9 @@ pub(super) enum PathKind { kind: AttrKind, annotated_item_kind: Option, }, - Derive, + Derive { + existing_derives: FxHashSet, + }, /// Path in item position, that is inside an (Assoc)ItemList Item { kind: ItemListKind, @@ -332,8 +334,6 @@ pub(crate) struct CompletionContext<'a> { pub(super) pattern_ctx: Option, pub(super) qualifier_ctx: QualifierCtx, - pub(super) existing_derives: FxHashSet, - pub(super) locals: FxHashMap, } @@ -556,7 +556,6 @@ pub(super) fn new( ident_ctx: IdentContext::UnexpandedAttrTT { fake_attribute_under_caret: None }, pattern_ctx: None, qualifier_ctx: Default::default(), - existing_derives: Default::default(), locals, }; ctx.expand_and_fill( diff --git a/crates/ide-completion/src/context/analysis.rs b/crates/ide-completion/src/context/analysis.rs index 8d38677df69..1989c3365f5 100644 --- a/crates/ide-completion/src/context/analysis.rs +++ b/crates/ide-completion/src/context/analysis.rs @@ -339,14 +339,6 @@ fn fill( // Overwrite the path kind for derives if let Some((original_file, file_with_fake_ident, offset, origin_attr)) = derive_ctx { - self.existing_derives = self - .sema - .resolve_derive_macro(&origin_attr) - .into_iter() - .flatten() - .flatten() - .collect(); - if let Some(ast::NameLike::NameRef(name_ref)) = find_node_at_offset(&file_with_fake_ident, offset) { @@ -354,7 +346,15 @@ fn fill( let (mut nameref_ctx, _, _) = Self::classify_name_ref(&self.sema, &original_file, name_ref, parent); if let Some(NameRefKind::Path(path_ctx)) = &mut nameref_ctx.kind { - path_ctx.kind = PathKind::Derive; + path_ctx.kind = PathKind::Derive { + existing_derives: self + .sema + .resolve_derive_macro(&origin_attr) + .into_iter() + .flatten() + .flatten() + .collect(), + }; } self.ident_ctx = IdentContext::NameRef(nameref_ctx); return Some(());