Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prioritize import suggestions based on the expected type #15627

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/ide-completion/src/completions/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ impl Foo { fn foo(&self) { $0 } }"#,
expect![[r#"
fd self.field i32
lc self &Foo
sp Self
st Foo
bt u32
sp Self Foo
st Foo Foo
bt u32 u32
me self.foo() fn(&self)
"#]],
);
Expand All @@ -954,9 +954,9 @@ impl Foo { fn foo(&mut self) { $0 } }"#,
expect![[r#"
fd self.0 i32
lc self &mut Foo
sp Self
st Foo
bt u32
sp Self Foo
st Foo Foo
bt u32 u32
me self.foo() fn(&mut self)
"#]],
);
Expand Down
30 changes: 15 additions & 15 deletions crates/ide-completion/src/completions/item_list/trait_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ impl Test for T {
}
",
expect![[r#"
sp Self
st T
sp Self T
st T T
tt Test
bt u32
bt u32 u32
"#]],
);

Expand Down Expand Up @@ -526,10 +526,10 @@ impl Test for T {
}
",
expect![[r#"
sp Self
st T
sp Self T
st T T
tt Test
bt u32
bt u32 u32
"#]],
);

Expand All @@ -543,10 +543,10 @@ impl Test for T {
}
",
expect![[r#"
sp Self
st T
sp Self T
st T T
tt Test
bt u32
bt u32 u32
"#]],
);

Expand All @@ -562,10 +562,10 @@ impl Test for T {
}
",
expect![[r#"
sp Self
st T
sp Self T
st T T
tt Test
bt u32
bt u32 u32
"#]],
);

Expand Down Expand Up @@ -610,10 +610,10 @@ impl Test for T {
}
",
expect![[r#"
sp Self
st T
sp Self T
st T T
tt Test
bt u32
bt u32 u32
"#]],
);

Expand Down
4 changes: 2 additions & 2 deletions crates/ide-completion/src/completions/use_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ pub(crate) fn complete_use_path(

if add_resolution {
let mut builder = Builder::from_resolution(ctx, path_ctx, name, def);
builder.set_relevance(CompletionRelevance {
builder.with_relevance(|r| CompletionRelevance {
is_name_already_imported,
..Default::default()
..r
});
acc.add(builder.build(ctx.db));
}
Expand Down
9 changes: 8 additions & 1 deletion crates/ide-completion/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! See `CompletionItem` structure.

use std::fmt;
use std::{fmt, mem};

use hir::Mutability;
use ide_db::{
Expand Down Expand Up @@ -570,6 +570,13 @@ impl Builder {
self.relevance = relevance;
self
}
pub(crate) fn with_relevance(
&mut self,
relevance: impl FnOnce(CompletionRelevance) -> CompletionRelevance,
) -> &mut Builder {
self.relevance = relevance(mem::take(&mut self.relevance));
self
}
pub(crate) fn trigger_call_info(&mut self) -> &mut Builder {
self.trigger_call_info = true;
self
Expand Down