Skip to content

Commit 129545f

Browse files
authored
Merge pull request rust-lang#19325 from Veykril/push-sxyvwwsmtxrr
Rank ADT constructors as constructors for completion scoring
2 parents 60da021 + e1912f8 commit 129545f

File tree

2 files changed

+102
-12
lines changed

2 files changed

+102
-12
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/render.rs

+94-10
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,24 @@ fn main() { Foo::Fo$0 }
11511151
),
11521152
lookup: "Foo{}",
11531153
detail: "Foo { x: i32, y: i32 }",
1154+
relevance: CompletionRelevance {
1155+
exact_name_match: false,
1156+
type_match: None,
1157+
is_local: false,
1158+
trait_: None,
1159+
is_name_already_imported: false,
1160+
requires_import: false,
1161+
is_private_editable: false,
1162+
postfix_match: None,
1163+
function: Some(
1164+
CompletionRelevanceFn {
1165+
has_params: true,
1166+
has_self_param: false,
1167+
return_type: DirectConstructor,
1168+
},
1169+
),
1170+
is_skipping_completion: false,
1171+
},
11541172
trigger_call_info: true,
11551173
},
11561174
]
@@ -1183,6 +1201,24 @@ fn main() { Foo::Fo$0 }
11831201
),
11841202
lookup: "Foo()",
11851203
detail: "Foo(i32, i32)",
1204+
relevance: CompletionRelevance {
1205+
exact_name_match: false,
1206+
type_match: None,
1207+
is_local: false,
1208+
trait_: None,
1209+
is_name_already_imported: false,
1210+
requires_import: false,
1211+
is_private_editable: false,
1212+
postfix_match: None,
1213+
function: Some(
1214+
CompletionRelevanceFn {
1215+
has_params: true,
1216+
has_self_param: false,
1217+
return_type: DirectConstructor,
1218+
},
1219+
),
1220+
is_skipping_completion: false,
1221+
},
11861222
trigger_call_info: true,
11871223
},
11881224
]
@@ -1261,6 +1297,24 @@ fn main() { Foo::Fo$0 }
12611297
Variant,
12621298
),
12631299
detail: "Foo",
1300+
relevance: CompletionRelevance {
1301+
exact_name_match: false,
1302+
type_match: None,
1303+
is_local: false,
1304+
trait_: None,
1305+
is_name_already_imported: false,
1306+
requires_import: false,
1307+
is_private_editable: false,
1308+
postfix_match: None,
1309+
function: Some(
1310+
CompletionRelevanceFn {
1311+
has_params: false,
1312+
has_self_param: false,
1313+
return_type: DirectConstructor,
1314+
},
1315+
),
1316+
is_skipping_completion: false,
1317+
},
12641318
trigger_call_info: true,
12651319
},
12661320
]
@@ -1335,7 +1389,13 @@ fn main() { let _: m::Spam = S$0 }
13351389
requires_import: false,
13361390
is_private_editable: false,
13371391
postfix_match: None,
1338-
function: None,
1392+
function: Some(
1393+
CompletionRelevanceFn {
1394+
has_params: true,
1395+
has_self_param: false,
1396+
return_type: DirectConstructor,
1397+
},
1398+
),
13391399
is_skipping_completion: false,
13401400
},
13411401
trigger_call_info: true,
@@ -1365,7 +1425,13 @@ fn main() { let _: m::Spam = S$0 }
13651425
requires_import: false,
13661426
is_private_editable: false,
13671427
postfix_match: None,
1368-
function: None,
1428+
function: Some(
1429+
CompletionRelevanceFn {
1430+
has_params: false,
1431+
has_self_param: false,
1432+
return_type: DirectConstructor,
1433+
},
1434+
),
13691435
is_skipping_completion: false,
13701436
},
13711437
trigger_call_info: true,
@@ -1590,6 +1656,24 @@ use self::E::*;
15901656
documentation: Documentation(
15911657
"variant docs",
15921658
),
1659+
relevance: CompletionRelevance {
1660+
exact_name_match: false,
1661+
type_match: None,
1662+
is_local: false,
1663+
trait_: None,
1664+
is_name_already_imported: false,
1665+
requires_import: false,
1666+
is_private_editable: false,
1667+
postfix_match: None,
1668+
function: Some(
1669+
CompletionRelevanceFn {
1670+
has_params: false,
1671+
has_self_param: false,
1672+
return_type: DirectConstructor,
1673+
},
1674+
),
1675+
is_skipping_completion: false,
1676+
},
15931677
trigger_call_info: true,
15941678
},
15951679
CompletionItem {
@@ -2081,8 +2165,8 @@ fn main() {
20812165
}
20822166
"#,
20832167
expect![[r#"
2084-
lc ssss S [type+local]
20852168
st S S [type]
2169+
lc ssss S [type+local]
20862170
st S S [type]
20872171
ex ssss [type]
20882172
ex S [type]
@@ -2153,14 +2237,14 @@ fn main() {
21532237
}
21542238
"#,
21552239
expect![[r#"
2240+
st S S []
2241+
st &S [type]
21562242
ex core::ops::Deref::deref(&t) [type_could_unify]
21572243
lc m i32 [local]
21582244
lc t T [local]
21592245
lc &t [type+local]
21602246
st S S []
21612247
st &S [type]
2162-
st S S []
2163-
st &S [type]
21642248
st T T []
21652249
st &T [type]
21662250
fn foo(…) fn(&S) []
@@ -2202,14 +2286,14 @@ fn main() {
22022286
}
22032287
"#,
22042288
expect![[r#"
2289+
st S S []
2290+
st &mut S [type]
22052291
ex core::ops::DerefMut::deref_mut(&mut t) [type_could_unify]
22062292
lc m i32 [local]
22072293
lc t T [local]
22082294
lc &mut t [type+local]
22092295
st S S []
22102296
st &mut S [type]
2211-
st S S []
2212-
st &mut S [type]
22132297
st T T []
22142298
st &mut T [type]
22152299
fn foo(…) fn(&mut S) []
@@ -2306,9 +2390,9 @@ fn main() {
23062390
}
23072391
"#,
23082392
expect![[r#"
2309-
ex core::ops::Deref::deref(&bar()) [type_could_unify]
23102393
st S S []
23112394
st &S [type]
2395+
ex core::ops::Deref::deref(&bar()) [type_could_unify]
23122396
st S S []
23132397
st &S [type]
23142398
st T T []
@@ -2827,11 +2911,11 @@ fn foo() {
28272911
}
28282912
"#,
28292913
expect![[r#"
2914+
ev Foo::B Foo::B [type_could_unify]
2915+
ev Foo::A(…) Foo::A(T) [type_could_unify]
28302916
lc foo Foo<u32> [type+local]
28312917
ex foo [type]
28322918
ex Foo::B [type]
2833-
ev Foo::A(…) Foo::A(T) [type_could_unify]
2834-
ev Foo::B Foo::B [type_could_unify]
28352919
en Foo Foo<{unknown}> [type_could_unify]
28362920
fn foo() fn() []
28372921
fn bar() fn() -> Foo<u8> []

src/tools/rust-analyzer/crates/ide-completion/src/render/literal.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ide_db::{
88

99
use crate::{
1010
context::{CompletionContext, PathCompletionCtx, PathKind},
11-
item::{Builder, CompletionItem},
11+
item::{Builder, CompletionItem, CompletionRelevanceFn},
1212
render::{
1313
compute_type_match,
1414
variant::{
@@ -17,7 +17,7 @@ use crate::{
1717
},
1818
RenderContext,
1919
},
20-
CompletionItemKind, CompletionRelevance,
20+
CompletionItemKind, CompletionRelevance, CompletionRelevanceReturnType,
2121
};
2222

2323
pub(crate) fn render_variant_lit(
@@ -131,6 +131,12 @@ fn render(
131131
let ty = thing.ty(db);
132132
item.set_relevance(CompletionRelevance {
133133
type_match: compute_type_match(ctx.completion, &ty),
134+
// function is a misnomer here, this is more about constructor information
135+
function: Some(CompletionRelevanceFn {
136+
has_params: !fields.is_empty(),
137+
has_self_param: false,
138+
return_type: CompletionRelevanceReturnType::DirectConstructor,
139+
}),
134140
..ctx.completion_relevance()
135141
});
136142

0 commit comments

Comments
 (0)