Skip to content

Commit dc31cef

Browse files
committed
Auto merge of rust-lang#16268 - Veykril:method-trait-completion-limit, r=Veykril
Remove completion limit for trait importing method completions Fixes rust-lang/rust-analyzer#16075 The < 3 char limit never applied to methods and the amount of completions generated due this is not absolutely massive as not all traits in a project are ever applicable so there is little reason to employ the limit here. Especially as it limits the number of traits we consider, not items (after my changes yesterday), and the number of traits is not the slowing factor here. Tested this in r-a where we have ~800 traits project wide and even when ~260 are applicable there was no noticable slow down from it.
2 parents 11b0126 + 4f75e0f commit dc31cef

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

crates/ide-completion/src/tests/flyimport.rs

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ fn main() {
599599
expect![[r#"
600600
fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
601601
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
602+
me random_method(…) (use dep::test_mod::TestTrait) fn(&self) DEPRECATED
602603
"#]],
603604
);
604605
}

crates/ide-db/src/imports/import_assets.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -500,23 +500,25 @@ fn trait_applicable_items(
500500
let related_traits = inherent_traits.chain(env_traits).collect::<FxHashSet<_>>();
501501

502502
let mut required_assoc_items = FxHashSet::default();
503-
let trait_candidates = items_locator::items_with_name(
503+
let trait_candidates: FxHashSet<_> = items_locator::items_with_name(
504504
sema,
505505
current_crate,
506506
trait_candidate.assoc_item_name.clone(),
507507
AssocSearchMode::AssocItemsOnly,
508508
)
509509
.filter_map(|input| item_as_assoc(db, input))
510510
.filter_map(|assoc| {
511+
if !trait_assoc_item && matches!(assoc, AssocItem::Const(_) | AssocItem::TypeAlias(_)) {
512+
return None;
513+
}
514+
511515
let assoc_item_trait = assoc.containing_trait(db)?;
512516
if related_traits.contains(&assoc_item_trait) {
513-
None
514-
} else {
515-
required_assoc_items.insert(assoc);
516-
Some(assoc_item_trait.into())
517+
return None;
517518
}
519+
required_assoc_items.insert(assoc);
520+
Some(assoc_item_trait.into())
518521
})
519-
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
520522
.collect();
521523

522524
let mut located_imports = FxHashSet::default();
@@ -531,11 +533,6 @@ fn trait_applicable_items(
531533
None,
532534
|assoc| {
533535
if required_assoc_items.contains(&assoc) {
534-
if let AssocItem::Function(f) = assoc {
535-
if f.self_param(db).is_some() {
536-
return None;
537-
}
538-
}
539536
let located_trait = assoc.containing_trait(db)?;
540537
let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
541538
let import_path = trait_import_paths

0 commit comments

Comments
 (0)