mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #7957
7957: Fix labels for single import assists r=SomeoneToIgnore a=SomeoneToIgnore Before: ![image](https://user-images.githubusercontent.com/2690773/110609185-a26b8e00-8195-11eb-87be-d21b75817c22.png) After: ![image](https://user-images.githubusercontent.com/2690773/110609198-a5667e80-8195-11eb-8c58-9ae19ba71905.png) Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
commit
a9b1e5cde1
2 changed files with 12 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
|||
use ide_db::helpers::{
|
||||
import_assets::{ImportAssets, ImportCandidate},
|
||||
insert_use::{insert_use, ImportScope},
|
||||
item_name, mod_path_to_ast,
|
||||
mod_path_to_ast,
|
||||
};
|
||||
use syntax::{ast, AstNode, SyntaxNode};
|
||||
|
||||
|
@ -90,17 +90,13 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
|||
}
|
||||
|
||||
let range = ctx.sema.original_range(&syntax_under_caret).range;
|
||||
let group = import_group_message(import_assets.import_candidate());
|
||||
let group_label = group_label(import_assets.import_candidate());
|
||||
let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?;
|
||||
for import in proposed_imports {
|
||||
let name = match item_name(ctx.db(), import.original_item) {
|
||||
Some(name) => name,
|
||||
None => continue,
|
||||
};
|
||||
acc.add_group(
|
||||
&group,
|
||||
&group_label,
|
||||
AssistId("auto_import", AssistKind::QuickFix),
|
||||
format!("Import `{}`", name),
|
||||
format!("Import `{}`", import.import_path),
|
||||
range,
|
||||
|builder| {
|
||||
let rewriter =
|
||||
|
@ -126,7 +122,7 @@ pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets,
|
|||
}
|
||||
}
|
||||
|
||||
fn import_group_message(import_candidate: &ImportCandidate) -> GroupLabel {
|
||||
fn group_label(import_candidate: &ImportCandidate) -> GroupLabel {
|
||||
let name = match import_candidate {
|
||||
ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()),
|
||||
ImportCandidate::TraitAssocItem(candidate) => {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::iter;
|
|||
use hir::AsAssocItem;
|
||||
use ide_db::helpers::{
|
||||
import_assets::{ImportCandidate, LocatedImport},
|
||||
item_name, mod_path_to_ast,
|
||||
mod_path_to_ast,
|
||||
};
|
||||
use ide_db::RootDatabase;
|
||||
use syntax::{
|
||||
|
@ -78,7 +78,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
|||
acc.add_group(
|
||||
&group_label,
|
||||
AssistId("qualify_path", AssistKind::QuickFix),
|
||||
label(ctx.db(), candidate, &import),
|
||||
label(candidate, &import),
|
||||
range,
|
||||
|builder| {
|
||||
qualify_candidate.qualify(
|
||||
|
@ -199,21 +199,17 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel {
|
|||
GroupLabel(format!("Qualify {}", name))
|
||||
}
|
||||
|
||||
fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String {
|
||||
let display_path = match item_name(db, import.original_item) {
|
||||
Some(display_path) => display_path.to_string(),
|
||||
None => "{unknown}".to_string(),
|
||||
};
|
||||
fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
|
||||
match candidate {
|
||||
ImportCandidate::Path(candidate) => {
|
||||
if candidate.qualifier.is_some() {
|
||||
format!("Qualify with `{}`", display_path)
|
||||
format!("Qualify with `{}`", import.import_path)
|
||||
} else {
|
||||
format!("Qualify as `{}`", display_path)
|
||||
format!("Qualify as `{}`", import.import_path)
|
||||
}
|
||||
}
|
||||
ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", display_path),
|
||||
ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", display_path),
|
||||
ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path),
|
||||
ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue