Skip to content

Commit 0b68402

Browse files
Merge pull request #18988 from ChayimFriedman2/iter-relevance
fix: Sort completion items that skip `await` and `iter()` behind those that don't
2 parents 2c040c0 + 8e0bc9f commit 0b68402

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

crates/ide-completion/src/item.rs

+9
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ pub struct CompletionRelevance {
181181
pub postfix_match: Option<CompletionRelevancePostfixMatch>,
182182
/// This is set for items that are function (associated or method)
183183
pub function: Option<CompletionRelevanceFn>,
184+
/// true when there is an `await.method()` or `iter().method()` completion.
185+
pub is_skipping_completion: bool,
184186
}
185187
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
186188
pub struct CompletionRelevanceTraitInfo {
@@ -269,6 +271,7 @@ impl CompletionRelevance {
269271
postfix_match,
270272
trait_,
271273
function,
274+
is_skipping_completion,
272275
} = self;
273276

274277
// only applicable for completions within use items
@@ -296,6 +299,12 @@ impl CompletionRelevance {
296299
score -= 5;
297300
}
298301
}
302+
303+
// Lower rank for completions that skip `await` and `iter()`.
304+
if is_skipping_completion {
305+
score -= 7;
306+
}
307+
299308
// lower rank for items that need an import
300309
if requires_import {
301310
score -= 1;

crates/ide-completion/src/render.rs

+16
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ pub(crate) fn render_field(
141141
item.set_relevance(CompletionRelevance {
142142
type_match: compute_type_match(ctx.completion, ty),
143143
exact_name_match: compute_exact_name_match(ctx.completion, &name),
144+
is_skipping_completion: receiver.is_some(),
144145
..CompletionRelevance::default()
145146
});
146147
item.detail(ty.display(db, ctx.completion.edition).to_string())
@@ -213,6 +214,10 @@ pub(crate) fn render_tuple_field(
213214
);
214215
item.detail(ty.display(ctx.db(), ctx.completion.edition).to_string())
215216
.lookup_by(field.to_string());
217+
item.set_relevance(CompletionRelevance {
218+
is_skipping_completion: receiver.is_some(),
219+
..ctx.completion_relevance()
220+
});
216221
item.build(ctx.db())
217222
}
218223

@@ -1333,6 +1338,7 @@ fn main() { let _: m::Spam = S$0 }
13331338
is_private_editable: false,
13341339
postfix_match: None,
13351340
function: None,
1341+
is_skipping_completion: false,
13361342
},
13371343
trigger_call_info: true,
13381344
},
@@ -1362,6 +1368,7 @@ fn main() { let _: m::Spam = S$0 }
13621368
is_private_editable: false,
13631369
postfix_match: None,
13641370
function: None,
1371+
is_skipping_completion: false,
13651372
},
13661373
trigger_call_info: true,
13671374
},
@@ -1451,6 +1458,7 @@ fn foo() { A { the$0 } }
14511458
is_private_editable: false,
14521459
postfix_match: None,
14531460
function: None,
1461+
is_skipping_completion: false,
14541462
},
14551463
},
14561464
]
@@ -1509,6 +1517,7 @@ impl S {
15091517
return_type: Other,
15101518
},
15111519
),
1520+
is_skipping_completion: false,
15121521
},
15131522
},
15141523
CompletionItem {
@@ -1651,6 +1660,7 @@ fn foo(s: S) { s.$0 }
16511660
return_type: Other,
16521661
},
16531662
),
1663+
is_skipping_completion: false,
16541664
},
16551665
},
16561666
]
@@ -1862,6 +1872,7 @@ fn f() -> i32 {
18621872
is_private_editable: false,
18631873
postfix_match: None,
18641874
function: None,
1875+
is_skipping_completion: false,
18651876
},
18661877
},
18671878
]
@@ -2622,6 +2633,7 @@ fn foo(f: Foo) { let _: &u32 = f.b$0 }
26222633
return_type: Other,
26232634
},
26242635
),
2636+
is_skipping_completion: false,
26252637
},
26262638
ref_match: "&@107",
26272639
},
@@ -2707,6 +2719,7 @@ fn foo() {
27072719
is_private_editable: false,
27082720
postfix_match: None,
27092721
function: None,
2722+
is_skipping_completion: false,
27102723
},
27112724
},
27122725
]
@@ -2764,6 +2777,7 @@ fn main() {
27642777
return_type: Other,
27652778
},
27662779
),
2780+
is_skipping_completion: false,
27672781
},
27682782
ref_match: "&@92",
27692783
},
@@ -3138,6 +3152,7 @@ fn main() {
31383152
is_private_editable: false,
31393153
postfix_match: None,
31403154
function: None,
3155+
is_skipping_completion: false,
31413156
},
31423157
},
31433158
CompletionItem {
@@ -3171,6 +3186,7 @@ fn main() {
31713186
is_private_editable: false,
31723187
postfix_match: None,
31733188
function: None,
3189+
is_skipping_completion: false,
31743190
},
31753191
},
31763192
]

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

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn render(
123123
exact_name_match: compute_exact_name_match(completion, &call),
124124
function,
125125
trait_: trait_info,
126+
is_skipping_completion: matches!(func_kind, FuncKind::Method(_, Some(_))),
126127
..ctx.completion_relevance()
127128
});
128129

0 commit comments

Comments
 (0)