diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 09:37:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 09:37:08 +0000 |
commit | 09412d85fc3137d6ada3b27170e14c287f1a1191 (patch) | |
tree | ac01ec54df0cebba975c82008482319820ce8757 /crates/ide_assists/src/handlers | |
parent | 2280f62a40f31d83fd79b62c46dd3d610354d78c (diff) | |
parent | 56a7d246d59d9429304b82bce2f1e71b632c5737 (diff) |
Merge #8123
8123: Do not display unqualified assoc item completions r=SomeoneToIgnore a=SomeoneToIgnore
Part of https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/autoimport.20weirdness
Removes all flyimport completions for any unqualified associated type, effectively reverting https://github.com/rust-analyzer/rust-analyzer/pull/8095
I've explained the reasoning in the corresponding FIXME and open to discussions.
As an alternative way, we could add yet another parameter in the method that's used by the `qualify_path` and enable it for the qualify assists only.
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r-- | crates/ide_assists/src/handlers/qualify_path.rs | 1 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | 35 |
2 files changed, 21 insertions, 15 deletions
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index e7444f7db..f91770a76 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs | |||
@@ -536,6 +536,7 @@ fn main() { | |||
536 | } | 536 | } |
537 | 537 | ||
538 | #[test] | 538 | #[test] |
539 | #[ignore = "FIXME: non-trait assoc items completion is unsupported yet, see FIXME in the import_assets.rs for more details"] | ||
539 | fn associated_struct_const_unqualified() { | 540 | fn associated_struct_const_unqualified() { |
540 | check_assist( | 541 | check_assist( |
541 | qualify_path, | 542 | qualify_path, |
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index 88fe2fe90..2608b56da 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use hir::ModuleDef; | 1 | use hir::ModuleDef; |
2 | use ide_db::helpers::mod_path_to_ast; | 2 | use ide_db::helpers::{import_assets::NameToImport, mod_path_to_ast}; |
3 | use ide_db::items_locator; | 3 | use ide_db::items_locator; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | use syntax::{ | 5 | use syntax::{ |
@@ -65,20 +65,25 @@ pub(crate) fn replace_derive_with_manual_impl( | |||
65 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; | 65 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; |
66 | let current_crate = current_module.krate(); | 66 | let current_crate = current_module.krate(); |
67 | 67 | ||
68 | let found_traits = | 68 | let found_traits = items_locator::items_with_name( |
69 | items_locator::with_exact_name(&ctx.sema, current_crate, trait_token.text().to_string()) | 69 | &ctx.sema, |
70 | .into_iter() | 70 | current_crate, |
71 | .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { | 71 | NameToImport::Exact(trait_token.text().to_string()), |
72 | ModuleDef::Trait(trait_) => Some(trait_), | 72 | items_locator::AssocItemSearch::Exclude, |
73 | _ => None, | 73 | Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT), |
74 | }) | 74 | ) |
75 | .flat_map(|trait_| { | 75 | .into_iter() |
76 | current_module | 76 | .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { |
77 | .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) | 77 | ModuleDef::Trait(trait_) => Some(trait_), |
78 | .as_ref() | 78 | _ => None, |
79 | .map(mod_path_to_ast) | 79 | }) |
80 | .zip(Some(trait_)) | 80 | .flat_map(|trait_| { |
81 | }); | 81 | current_module |
82 | .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) | ||
83 | .as_ref() | ||
84 | .map(mod_path_to_ast) | ||
85 | .zip(Some(trait_)) | ||
86 | }); | ||
82 | 87 | ||
83 | let mut no_traits_found = true; | 88 | let mut no_traits_found = true; |
84 | for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { | 89 | for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { |