Skip to content

Commit a629d6f

Browse files
committed
fix: tests
1 parent 0cb9103 commit a629d6f

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

crates/ide-completion/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ pub struct CompletionRelevanceAssociatedFn {
215215

216216
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
217217
pub enum CompletionRelevanceAssociatedFnType {
218-
Unknown,
218+
Other,
219219
/// Returns a type that is expected in this context
220220
ReturnsExpectedType,
221221
/// Returns the Self type of the impl/trait
@@ -298,7 +298,7 @@ impl CompletionRelevance {
298298
CompletionRelevanceAssociatedFnType::DirectConstructor => 15,
299299
CompletionRelevanceAssociatedFnType::Builder => 10,
300300
CompletionRelevanceAssociatedFnType::Constructor => 5,
301-
CompletionRelevanceAssociatedFnType::Unknown => 0,
301+
CompletionRelevanceAssociatedFnType::Other => 0,
302302
} + if !asf.has_args { 5 } else { 0 })
303303
.unwrap_or_default();
304304

crates/ide-completion/src/render.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,24 @@ impl S {
13161316
documentation: Documentation(
13171317
"Method docs",
13181318
),
1319+
relevance: CompletionRelevance {
1320+
exact_name_match: false,
1321+
type_match: None,
1322+
is_local: false,
1323+
is_item_from_trait: false,
1324+
is_name_already_imported: false,
1325+
requires_import: false,
1326+
is_op_method: false,
1327+
is_private_editable: false,
1328+
postfix_match: None,
1329+
is_definite: false,
1330+
associated_fn: Some(
1331+
CompletionRelevanceAssociatedFn {
1332+
has_args: true,
1333+
ty: Other,
1334+
},
1335+
),
1336+
},
13191337
},
13201338
CompletionItem {
13211339
label: "foo",
@@ -1433,7 +1451,10 @@ fn foo(s: S) { s.$0 }
14331451
postfix_match: None,
14341452
is_definite: false,
14351453
associated_fn: Some(
1436-
ReturnsExpectedType,
1454+
CompletionRelevanceAssociatedFn {
1455+
has_args: true,
1456+
ty: Other,
1457+
},
14371458
),
14381459
},
14391460
},
@@ -2114,7 +2135,10 @@ fn foo(f: Foo) { let _: &u32 = f.b$0 }
21142135
postfix_match: None,
21152136
is_definite: false,
21162137
associated_fn: Some(
2117-
DirectConstructorWithArgs,
2138+
CompletionRelevanceAssociatedFn {
2139+
has_args: true,
2140+
ty: Other,
2141+
},
21182142
),
21192143
},
21202144
ref_match: "&@107",
@@ -2240,7 +2264,10 @@ fn main() {
22402264
postfix_match: None,
22412265
is_definite: false,
22422266
associated_fn: Some(
2243-
DirectConstructor,
2267+
CompletionRelevanceAssociatedFn {
2268+
has_args: false,
2269+
ty: Other,
2270+
},
22442271
),
22452272
},
22462273
ref_match: "&@92",

crates/ide-completion/src/render/function.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn compute_associated_fn(
170170
}
171171

172172
let ret_type = func.ret_type(db);
173+
let ret_unit_type = ret_type.is_unit();
173174
let self_ty = match func_kind {
174175
FuncKind::Function(PathCompletionCtx {
175176
qualified: Qualified::With { path, .. }, ..
@@ -185,7 +186,10 @@ fn compute_associated_fn(
185186
})
186187
.unwrap_or_else(|| (false, false));
187188

188-
let ty = if !returns_self && ctx.completion.expected_type.as_ref() == Some(&ret_type) {
189+
let ty = if !returns_self
190+
&& !ret_unit_type
191+
&& ctx.completion.expected_type.as_ref() == Some(&ret_type)
192+
{
189193
// impl Foo { fn baz(&self) -> u32 { 0 } }
190194
// let _: u32 = foo.$0; // baz is preffered as it returns expected u32
191195
CompletionRelevanceAssociatedFnType::ReturnsExpectedType
@@ -199,7 +203,7 @@ fn compute_associated_fn(
199203
// fn() -> A
200204
CompletionRelevanceAssociatedFnType::DirectConstructor
201205
} else {
202-
CompletionRelevanceAssociatedFnType::Unknown
206+
CompletionRelevanceAssociatedFnType::Other
203207
};
204208

205209
Some(CompletionRelevanceAssociatedFn { ty, has_args: !func.assoc_fn_params(db).is_empty() })

0 commit comments

Comments
 (0)