Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/render.rs')
-rw-r--r--crates/ide-completion/src/render.rs65
1 files changed, 33 insertions, 32 deletions
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index bc71c1da2b..f559aae789 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -71,7 +71,7 @@ impl<'a, 'db> RenderContext<'a, 'db> {
self.completion.config.snippet_cap
}
- fn db(&self) -> &'a RootDatabase {
+ fn db(&self) -> &'db RootDatabase {
self.completion.db
}
@@ -294,9 +294,9 @@ pub(crate) fn render_resolution_with_import_pat(
Some(render_resolution_pat(ctx, pattern_ctx, local_name, Some(import_edit), resolution))
}
-pub(crate) fn render_expr(
- ctx: &CompletionContext<'_, '_>,
- expr: &hir::term_search::Expr<'_>,
+pub(crate) fn render_expr<'db>(
+ ctx: &CompletionContext<'_, 'db>,
+ expr: &hir::term_search::Expr<'db>,
) -> Option<Builder> {
let mut i = 1;
let mut snippet_formatter = |ty: &hir::Type<'_>| {
@@ -341,7 +341,7 @@ pub(crate) fn render_expr(
"Autogenerated expression by term search",
)));
item.set_relevance(crate::CompletionRelevance {
- type_match: compute_type_match(ctx, &expr.ty(ctx.db)),
+ type_match: compute_type_match(ctx, &ctx.rebase_ty(&expr.ty(ctx.db))),
..Default::default()
});
for trait_ in expr.traits_used(ctx.db) {
@@ -405,8 +405,8 @@ fn render_resolution_pat(
}
}
-fn render_resolution_path(
- ctx: RenderContext<'_, '_>,
+fn render_resolution_path<'db>(
+ ctx: RenderContext<'_, 'db>,
path_ctx: &PathCompletionCtx<'_>,
local_name: hir::Name,
import_to_add: Option<LocatedImport>,
@@ -480,11 +480,12 @@ fn render_resolution_path(
}
adds_ret_type_arrow(completion, path_ctx, &mut item, insert_text.into());
- let mut set_item_relevance = |ty: Type<'_>| {
+ let mut set_item_relevance = |ty: Type<'db>| {
if !ty.is_unknown() {
item.detail(ty.display(db, krate).to_string());
}
+ let ty = completion.rebase_ty(&ty);
item.set_relevance(CompletionRelevance {
type_match: compute_type_match(completion, &ty),
exact_name_match: compute_exact_name_match(completion, &name),
@@ -688,8 +689,8 @@ fn compute_type_match(
// &mut ty -> &ty
if completion_ty.is_mutable_reference()
- && let Some(expected_type) = expected_type.remove_ref()
- && let Some(completion_ty) = completion_ty.remove_ref()
+ && let Some((expected_type, _)) = expected_type.as_reference()
+ && let Some((completion_ty, _)) = completion_ty.as_reference()
{
return match_types(ctx, &expected_type, &completion_ty);
}
@@ -718,12 +719,12 @@ fn compute_ref_match(
completion_ty: &hir::Type<'_>,
) -> Option<CompletionItemRefMode> {
let expected_type = ctx.expected_type.as_ref()?;
- let expected_without_ref = expected_type.remove_ref();
- let completion_without_ref = completion_ty.remove_ref();
+ let expected_without_ref = expected_type.as_reference();
+ let completion_without_ref = completion_ty.as_reference();
if expected_type.could_unify_with(ctx.db, completion_ty) {
return None;
}
- if let Some(expected_without_ref) = &expected_without_ref
+ if let Some((expected_without_ref, _)) = &expected_without_ref
&& (completion_without_ref.is_none()
|| completion_ty.could_unify_with(ctx.db, expected_without_ref))
&& completion_ty
@@ -739,7 +740,7 @@ fn compute_ref_match(
return Some(CompletionItemRefMode::Reference(mutability));
}
- if let Some(completion_without_ref) = completion_without_ref
+ if let Some((completion_without_ref, _)) = completion_without_ref
&& completion_without_ref == *expected_type
&& completion_without_ref.is_copy(ctx.db)
{
@@ -952,9 +953,9 @@ fn main() {
}
"#,
expect![[r#"
- st dep::test_mod_b::Struct {…} dep::test_mod_b::Struct { } [type_could_unify]
- ex dep::test_mod_b::Struct { } [type_could_unify]
- st Struct Struct [type_could_unify+requires_import]
+ st dep::test_mod_b::Struct {…} dep::test_mod_b::Struct { } [type]
+ ex dep::test_mod_b::Struct { } [type]
+ st Struct Struct [type+requires_import]
md dep:: []
fn main() fn() []
fn test(…) fn(Struct) []
@@ -992,7 +993,7 @@ fn main() {
}
"#,
expect![[r#"
- un Union Union [type_could_unify+requires_import]
+ un Union Union [type+requires_import]
md dep:: []
fn main() fn() []
fn test(…) fn(Union) []
@@ -1028,9 +1029,9 @@ fn main() {
}
"#,
expect![[r#"
- ev dep::test_mod_b::Enum::variant dep::test_mod_b::Enum::variant [type_could_unify]
- ex dep::test_mod_b::Enum::variant [type_could_unify]
- en Enum Enum [type_could_unify+requires_import]
+ ev dep::test_mod_b::Enum::variant dep::test_mod_b::Enum::variant [type]
+ ex dep::test_mod_b::Enum::variant [type]
+ en Enum Enum [type+requires_import]
md dep:: []
fn main() fn() []
fn test(…) fn(Enum) []
@@ -1066,10 +1067,10 @@ fn main() {
}
"#,
expect![[r#"
- ev dep::test_mod_b::Enum::Variant dep::test_mod_b::Enum::Variant [type_could_unify]
- ev Variant Variant [type_could_unify+requires_import]
+ ev dep::test_mod_b::Enum::Variant dep::test_mod_b::Enum::Variant [type]
+ ev Variant Variant [type+requires_import]
+ ex dep::test_mod_b::Enum::Variant [type]
ev Variant Variant [requires_import]
- ex dep::test_mod_b::Enum::Variant [type_could_unify]
md dep:: []
fn main() fn() []
fn test(…) fn(Enum) []
@@ -1132,7 +1133,7 @@ fn main() {
}
"#,
expect![[r#"
- ct CONST i32 [type_could_unify+requires_import]
+ ct CONST i32 [type+requires_import]
md dep:: []
fn main() fn() []
fn test(…) fn(i32) []
@@ -1164,7 +1165,7 @@ fn main() {
}
"#,
expect![[r#"
- sc STATIC i32 [type_could_unify+requires_import]
+ sc STATIC i32 [type+requires_import]
md dep:: []
fn main() fn() []
fn test(…) fn(i32) []
@@ -3145,7 +3146,7 @@ fn main() {
st &mut S(…) [type]
lc ssss S<u32> [local]
lc &mut ssss [type+local]
- st S S<{unknown}> []
+ st S S<T> []
fn foo(…) fn(&mut S<T>) []
fn main() fn() []
"#]],
@@ -3168,7 +3169,7 @@ fn main() {
expect![[r#"
ex ssss.0 [type_could_unify]
lc ssss S<{unknown}> [local]
- st S S<{unknown}> []
+ st S S<T> []
md core:: []
fn foo(…) fn(&u32) []
fn main() fn() []
@@ -3916,9 +3917,9 @@ fn foo() {
lc foo Foo<u32> [type+local]
ex Foo::B [type]
ex foo [type]
- en Foo Foo<{unknown}> [type_could_unify]
+ en Foo Foo<T> [type_could_unify]
+ fn baz() fn() -> Foo<T> [type_could_unify]
fn bar() fn() -> Foo<u8> []
- fn baz() fn() -> Foo<T> []
fn foo() fn() []
"#]],
);
@@ -3948,6 +3949,7 @@ fn main() {
&[CompletionItemKind::Snippet, CompletionItemKind::SymbolKind(SymbolKind::Method)],
expect![[r#"
sn not !expr [snippet]
+ me not() fn(self) -> <Self as Not>::Output [type_could_unify+requires_import]
sn box Box::new(expr) []
sn call function(expr) []
sn const const {} []
@@ -3961,7 +3963,6 @@ fn main() {
sn return return expr []
sn unsafe unsafe {} []
sn while while expr {} []
- me not() fn(self) -> <Self as Not>::Output [requires_import]
"#]],
);
}
@@ -4012,7 +4013,7 @@ enum Foo {
en Foo Foo []
st Other Other []
sp Self Foo []
- st Vec<…> Vec<{unknown}> []
+ st Vec<…> Vec<T> []
"#]],
);
}