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 <mail4score@gmail.com>
This commit is contained in:
bors[bot] 2021-03-21 09:37:08 +00:00 committed by GitHub
commit 09412d85fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 255 additions and 229 deletions

View file

@ -14,7 +14,10 @@ mod completions;
use completions::flyimport::position_for_import;
use ide_db::{
base_db::FilePosition,
helpers::{import_assets::LocatedImport, insert_use::ImportScope},
helpers::{
import_assets::{LocatedImport, NameToImport},
insert_use::ImportScope,
},
items_locator, RootDatabase,
};
use text_edit::TextEdit;
@ -151,15 +154,20 @@ pub fn resolve_completion_edits(
let current_module = ctx.sema.scope(position_for_import).module()?;
let current_crate = current_module.krate();
let (import_path, item_to_import) =
items_locator::with_exact_name(&ctx.sema, current_crate, imported_name)
.into_iter()
.filter_map(|candidate| {
current_module
.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
.zip(Some(candidate))
})
.find(|(mod_path, _)| mod_path.to_string() == full_import_path)?;
let (import_path, item_to_import) = items_locator::items_with_name(
&ctx.sema,
current_crate,
NameToImport::Exact(imported_name),
items_locator::AssocItemSearch::Include,
Some(items_locator::DEFAULT_QUERY_SEARCH_LIMIT),
)
.into_iter()
.filter_map(|candidate| {
current_module
.find_use_path_prefixed(db, candidate, config.insert_use.prefix_kind)
.zip(Some(candidate))
})
.find(|(mod_path, _)| mod_path.to_string() == full_import_path)?;
let import =
LocatedImport::new(import_path.clone(), item_to_import, item_to_import, Some(import_path));