Auto merge of #16268 - Veykril:method-trait-completion-limit, r=Veykril

Remove completion limit for trait importing method completions

Fixes https://github.com/rust-lang/rust-analyzer/issues/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.
This commit is contained in:
bors 2024-01-05 11:14:37 +00:00
commit dc31cef5fc
2 changed files with 9 additions and 11 deletions

View File

@ -599,6 +599,7 @@ fn main() {
expect![[r#" expect![[r#"
fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED fn weird_function() (use dep::test_mod::TestTrait) fn() DEPRECATED
ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED ct SPECIAL_CONST (use dep::test_mod::TestTrait) u8 DEPRECATED
me random_method() (use dep::test_mod::TestTrait) fn(&self) DEPRECATED
"#]], "#]],
); );
} }

View File

@ -500,7 +500,7 @@ fn trait_applicable_items(
let related_traits = inherent_traits.chain(env_traits).collect::<FxHashSet<_>>(); let related_traits = inherent_traits.chain(env_traits).collect::<FxHashSet<_>>();
let mut required_assoc_items = FxHashSet::default(); let mut required_assoc_items = FxHashSet::default();
let trait_candidates = items_locator::items_with_name( let trait_candidates: FxHashSet<_> = items_locator::items_with_name(
sema, sema,
current_crate, current_crate,
trait_candidate.assoc_item_name.clone(), trait_candidate.assoc_item_name.clone(),
@ -508,15 +508,17 @@ fn trait_applicable_items(
) )
.filter_map(|input| item_as_assoc(db, input)) .filter_map(|input| item_as_assoc(db, input))
.filter_map(|assoc| { .filter_map(|assoc| {
if !trait_assoc_item && matches!(assoc, AssocItem::Const(_) | AssocItem::TypeAlias(_)) {
return None;
}
let assoc_item_trait = assoc.containing_trait(db)?; let assoc_item_trait = assoc.containing_trait(db)?;
if related_traits.contains(&assoc_item_trait) { if related_traits.contains(&assoc_item_trait) {
None return None;
} else { }
required_assoc_items.insert(assoc); required_assoc_items.insert(assoc);
Some(assoc_item_trait.into()) Some(assoc_item_trait.into())
}
}) })
.take(DEFAULT_QUERY_SEARCH_LIMIT.inner())
.collect(); .collect();
let mut located_imports = FxHashSet::default(); let mut located_imports = FxHashSet::default();
@ -531,11 +533,6 @@ fn trait_applicable_items(
None, None,
|assoc| { |assoc| {
if required_assoc_items.contains(&assoc) { if required_assoc_items.contains(&assoc) {
if let AssocItem::Function(f) = assoc {
if f.self_param(db).is_some() {
return None;
}
}
let located_trait = assoc.containing_trait(db)?; let located_trait = assoc.containing_trait(db)?;
let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
let import_path = trait_import_paths let import_path = trait_import_paths