Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/attribute/derive.rs')
-rw-r--r--crates/ide-completion/src/completions/attribute/derive.rs37
1 files changed, 15 insertions, 22 deletions
diff --git a/crates/ide-completion/src/completions/attribute/derive.rs b/crates/ide-completion/src/completions/attribute/derive.rs
index 0927d2f764..0e10f38153 100644
--- a/crates/ide-completion/src/completions/attribute/derive.rs
+++ b/crates/ide-completion/src/completions/attribute/derive.rs
@@ -5,23 +5,17 @@ use itertools::Itertools;
use syntax::SmolStr;
use crate::{
- context::{CompletionContext, PathCompletionCtx, PathKind, Qualified},
+ context::{CompletionContext, ExistingDerives, PathCompletionCtx, Qualified},
item::CompletionItem,
Completions,
};
-pub(crate) fn complete_derive(
+pub(crate) fn complete_derive_path(
acc: &mut Completions,
ctx: &CompletionContext,
- path_ctx: &PathCompletionCtx,
+ PathCompletionCtx { qualified, .. }: &PathCompletionCtx,
+ existing_derives: &ExistingDerives,
) {
- let (qualified, existing_derives) = match path_ctx {
- PathCompletionCtx { kind: PathKind::Derive { existing_derives }, qualified, .. } => {
- (qualified, existing_derives)
- }
- _ => return,
- };
-
let core = ctx.famous_defs().core();
match qualified {
@@ -35,15 +29,14 @@ pub(crate) fn complete_derive(
}
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
- let add_def = match def {
- ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => {
- !existing_derives.contains(&mac) && mac.is_derive(ctx.db)
+ match def {
+ ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac))
+ if !existing_derives.contains(&mac) && mac.is_derive(ctx.db) =>
+ {
+ acc.add_macro(ctx, mac, name)
}
- ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true,
- _ => false,
- };
- if add_def {
- acc.add_resolution(ctx, name, def);
+ ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) => acc.add_module(ctx, m, name),
+ _ => (),
}
}
}
@@ -57,8 +50,8 @@ pub(crate) fn complete_derive(
{
mac
}
- ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => {
- return acc.add_resolution(ctx, name, def);
+ ScopeDef::ModuleDef(hir::ModuleDef::Module(m)) => {
+ return acc.add_module(ctx, m, name);
}
_ => return,
};
@@ -66,7 +59,7 @@ pub(crate) fn complete_derive(
match (core, mac.module(ctx.db).krate()) {
// show derive dependencies for `core`/`std` derives
(Some(core), mac_krate) if core == mac_krate => {}
- _ => return acc.add_resolution(ctx, name, def),
+ _ => return acc.add_macro(ctx, mac, name),
};
let name_ = name.to_smol_str();
@@ -99,7 +92,7 @@ pub(crate) fn complete_derive(
item.lookup_by(lookup);
item.add_to(acc);
}
- None => acc.add_resolution(ctx, name, def),
+ None => acc.add_macro(ctx, mac, name),
}
});
acc.add_nameref_keywords_with_colon(ctx);