Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2f2ea77

Browse files
committed
Move existing_derives into PathKind::Derive
1 parent 531060f commit 2f2ea77

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

crates/ide-completion/src/completions/attribute/derive.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use crate::{
1111
};
1212

1313
pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
14-
let qualified = match ctx.path_context() {
15-
Some(&PathCompletionCtx { kind: PathKind::Derive, ref qualified, .. }) => qualified,
14+
let (qualified, existing_derives) = match ctx.path_context() {
15+
Some(PathCompletionCtx {
16+
kind: PathKind::Derive { existing_derives }, qualified, ..
17+
}) => (qualified, existing_derives),
1618
_ => return,
1719
};
1820

@@ -32,7 +34,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
3234
for (name, def) in module.scope(ctx.db, Some(ctx.module)) {
3335
let add_def = match def {
3436
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac)) => {
35-
!ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db)
37+
!existing_derives.contains(&mac) && mac.is_derive(ctx.db)
3638
}
3739
ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) => true,
3840
_ => false,
@@ -48,7 +50,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
4850
ctx.process_all_names(&mut |name, def| {
4951
let mac = match def {
5052
ScopeDef::ModuleDef(hir::ModuleDef::Macro(mac))
51-
if !ctx.existing_derives.contains(&mac) && mac.is_derive(ctx.db) =>
53+
if !existing_derives.contains(&mac) && mac.is_derive(ctx.db) =>
5254
{
5355
mac
5456
}
@@ -74,7 +76,7 @@ pub(crate) fn complete_derive(acc: &mut Completions, ctx: &CompletionContext) {
7476
let mut components = vec![derive_completion.label];
7577
components.extend(derive_completion.dependencies.iter().filter(
7678
|&&dependency| {
77-
!ctx.existing_derives
79+
!existing_derives
7880
.iter()
7981
.map(|it| it.name(ctx.db))
8082
.any(|it| it.to_smol_str() == dependency)

crates/ide-completion/src/completions/flyimport.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
120120
kind @ (PathKind::Expr { .. }
121121
| PathKind::Type { .. }
122122
| PathKind::Attr { .. }
123-
| PathKind::Derive
123+
| PathKind::Derive { .. }
124124
| PathKind::Pat),
125125
..
126126
})),
@@ -188,10 +188,10 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
188188
(PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),
189189
(PathKind::Attr { .. }, _) => false,
190190

191-
(PathKind::Derive, ItemInNs::Macros(mac)) => {
192-
mac.is_derive(ctx.db) && !ctx.existing_derives.contains(&mac)
191+
(PathKind::Derive { existing_derives }, ItemInNs::Macros(mac)) => {
192+
mac.is_derive(ctx.db) && !existing_derives.contains(&mac)
193193
}
194-
(PathKind::Derive, _) => false,
194+
(PathKind::Derive { .. }, _) => false,
195195
}
196196
};
197197

crates/ide-completion/src/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ pub(super) enum PathKind {
101101
kind: AttrKind,
102102
annotated_item_kind: Option<SyntaxKind>,
103103
},
104-
Derive,
104+
Derive {
105+
existing_derives: FxHashSet<hir::Macro>,
106+
},
105107
/// Path in item position, that is inside an (Assoc)ItemList
106108
Item {
107109
kind: ItemListKind,
@@ -332,8 +334,6 @@ pub(crate) struct CompletionContext<'a> {
332334
pub(super) pattern_ctx: Option<PatternContext>,
333335
pub(super) qualifier_ctx: QualifierCtx,
334336

335-
pub(super) existing_derives: FxHashSet<hir::Macro>,
336-
337337
pub(super) locals: FxHashMap<Name, Local>,
338338
}
339339

@@ -556,7 +556,6 @@ impl<'a> CompletionContext<'a> {
556556
ident_ctx: IdentContext::UnexpandedAttrTT { fake_attribute_under_caret: None },
557557
pattern_ctx: None,
558558
qualifier_ctx: Default::default(),
559-
existing_derives: Default::default(),
560559
locals,
561560
};
562561
ctx.expand_and_fill(

crates/ide-completion/src/context/analysis.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,22 +339,22 @@ impl<'a> CompletionContext<'a> {
339339

340340
// Overwrite the path kind for derives
341341
if let Some((original_file, file_with_fake_ident, offset, origin_attr)) = derive_ctx {
342-
self.existing_derives = self
343-
.sema
344-
.resolve_derive_macro(&origin_attr)
345-
.into_iter()
346-
.flatten()
347-
.flatten()
348-
.collect();
349-
350342
if let Some(ast::NameLike::NameRef(name_ref)) =
351343
find_node_at_offset(&file_with_fake_ident, offset)
352344
{
353345
let parent = name_ref.syntax().parent()?;
354346
let (mut nameref_ctx, _, _) =
355347
Self::classify_name_ref(&self.sema, &original_file, name_ref, parent);
356348
if let Some(NameRefKind::Path(path_ctx)) = &mut nameref_ctx.kind {
357-
path_ctx.kind = PathKind::Derive;
349+
path_ctx.kind = PathKind::Derive {
350+
existing_derives: self
351+
.sema
352+
.resolve_derive_macro(&origin_attr)
353+
.into_iter()
354+
.flatten()
355+
.flatten()
356+
.collect(),
357+
};
358358
}
359359
self.ident_ctx = IdentContext::NameRef(nameref_ctx);
360360
return Some(());

0 commit comments

Comments
 (0)