Skip to content

Commit 3e4f969

Browse files
committed
fix: tests
1 parent ab0ca80 commit 3e4f969

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
@@ -217,7 +217,7 @@ pub struct CompletionRelevanceAssociatedFn {
217217

218218
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
219219
pub enum CompletionRelevanceAssociatedFnType {
220-
Unknown,
220+
Other,
221221
/// Returns a type that is expected in this context
222222
ReturnsExpectedType,
223223
/// Returns the Self type of the impl/trait
@@ -304,7 +304,7 @@ impl CompletionRelevance {
304304
CompletionRelevanceAssociatedFnType::DirectConstructor => 15,
305305
CompletionRelevanceAssociatedFnType::Builder => 10,
306306
CompletionRelevanceAssociatedFnType::Constructor => 5,
307-
CompletionRelevanceAssociatedFnType::Unknown => 0,
307+
CompletionRelevanceAssociatedFnType::Other => 0,
308308
} + if !asf.has_args { 5 } else { 0 })
309309
.unwrap_or_default();
310310

crates/ide-completion/src/render.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,24 @@ impl S {
13191319
documentation: Documentation(
13201320
"Method docs",
13211321
),
1322+
relevance: CompletionRelevance {
1323+
exact_name_match: false,
1324+
type_match: None,
1325+
is_local: false,
1326+
is_item_from_trait: false,
1327+
is_name_already_imported: false,
1328+
requires_import: false,
1329+
is_op_method: false,
1330+
is_private_editable: false,
1331+
postfix_match: None,
1332+
is_definite: false,
1333+
associated_fn: Some(
1334+
CompletionRelevanceAssociatedFn {
1335+
has_args: true,
1336+
ty: Other,
1337+
},
1338+
),
1339+
},
13221340
},
13231341
CompletionItem {
13241342
label: "foo",
@@ -1436,7 +1454,10 @@ fn foo(s: S) { s.$0 }
14361454
postfix_match: None,
14371455
is_definite: false,
14381456
associated_fn: Some(
1439-
ReturnsExpectedType,
1457+
CompletionRelevanceAssociatedFn {
1458+
has_args: true,
1459+
ty: Other,
1460+
},
14401461
),
14411462
},
14421463
},
@@ -2117,7 +2138,10 @@ fn foo(f: Foo) { let _: &u32 = f.b$0 }
21172138
postfix_match: None,
21182139
is_definite: false,
21192140
associated_fn: Some(
2120-
DirectConstructorWithArgs,
2141+
CompletionRelevanceAssociatedFn {
2142+
has_args: true,
2143+
ty: Other,
2144+
},
21212145
),
21222146
},
21232147
ref_match: "&@107",
@@ -2244,7 +2268,10 @@ fn main() {
22442268
postfix_match: None,
22452269
is_definite: false,
22462270
associated_fn: Some(
2247-
DirectConstructor,
2271+
CompletionRelevanceAssociatedFn {
2272+
has_args: false,
2273+
ty: Other,
2274+
},
22482275
),
22492276
},
22502277
ref_match: "&@92",

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ fn compute_associated_fn(
174174
}
175175

176176
let ret_type = func.ret_type(db);
177+
let ret_unit_type = ret_type.is_unit();
177178
let self_ty = match func_kind {
178179
FuncKind::Function(PathCompletionCtx {
179180
qualified: Qualified::With { path, .. }, ..
@@ -189,7 +190,10 @@ fn compute_associated_fn(
189190
})
190191
.unwrap_or_else(|| (false, false));
191192

192-
let ty = if !returns_self && ctx.completion.expected_type.as_ref() == Some(&ret_type) {
193+
let ty = if !returns_self
194+
&& !ret_unit_type
195+
&& ctx.completion.expected_type.as_ref() == Some(&ret_type)
196+
{
193197
// impl Foo { fn baz(&self) -> u32 { 0 } }
194198
// let _: u32 = foo.$0; // baz is preffered as it returns expected u32
195199
CompletionRelevanceAssociatedFnType::ReturnsExpectedType
@@ -203,7 +207,7 @@ fn compute_associated_fn(
203207
// fn() -> A
204208
CompletionRelevanceAssociatedFnType::DirectConstructor
205209
} else {
206-
CompletionRelevanceAssociatedFnType::Unknown
210+
CompletionRelevanceAssociatedFnType::Other
207211
};
208212

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

0 commit comments

Comments
 (0)