mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Work towards better import labels
This commit is contained in:
parent
4d4ac1d4fa
commit
33c83e72b9
13 changed files with 242 additions and 238 deletions
|
@ -15,7 +15,7 @@ use completions::flyimport::position_for_import;
|
|||
use ide_db::{
|
||||
base_db::FilePosition,
|
||||
helpers::{import_assets::LocatedImport, insert_use::ImportScope},
|
||||
imports_locator, RootDatabase,
|
||||
items_locator, RootDatabase,
|
||||
};
|
||||
use text_edit::TextEdit;
|
||||
|
||||
|
@ -141,7 +141,6 @@ pub fn resolve_completion_edits(
|
|||
position: FilePosition,
|
||||
full_import_path: &str,
|
||||
imported_name: String,
|
||||
import_for_trait_assoc_item: bool,
|
||||
) -> Option<Vec<TextEdit>> {
|
||||
let ctx = CompletionContext::new(db, position, config)?;
|
||||
let position_for_import = position_for_import(&ctx, None)?;
|
||||
|
@ -151,19 +150,17 @@ pub fn resolve_completion_edits(
|
|||
let current_crate = current_module.krate();
|
||||
|
||||
let (import_path, item_to_import) =
|
||||
imports_locator::find_exact_imports(&ctx.sema, current_crate, imported_name)
|
||||
items_locator::with_for_exact_name(&ctx.sema, current_crate, imported_name)
|
||||
.into_iter()
|
||||
.filter_map(|candidate| {
|
||||
let item: hir::ItemInNs = candidate.either(Into::into, Into::into);
|
||||
current_module
|
||||
.find_use_path_prefixed(db, item, config.insert_use.prefix_kind)
|
||||
.zip(Some(item))
|
||||
.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, item_to_import, None);
|
||||
let import = LocatedImport::new(import_path, item_to_import, item_to_import);
|
||||
|
||||
ImportEdit { import_path, import_scope, import_for_trait_assoc_item }
|
||||
.to_text_edit(config.insert_use)
|
||||
.map(|edit| vec![edit])
|
||||
ImportEdit { import, import_scope }.to_text_edit(config.insert_use).map(|edit| vec![edit])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue