diff options
author | Kirill Bulatov <[email protected]> | 2021-03-10 09:30:25 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-10 09:30:25 +0000 |
commit | 94bb9cb9ee0e67048c6fdd90250add0cc71b073f (patch) | |
tree | dd2d37626f7122074cd86378b1118cef9dcce52f /crates/ide_assists/src/handlers | |
parent | 63715e1f732d94f090078d03591fe5569d8890c3 (diff) |
Fix labels for single import assists
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r-- | crates/ide_assists/src/handlers/auto_import.rs | 14 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/qualify_path.rs | 18 |
2 files changed, 12 insertions, 20 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 7caee8df0..7019039b9 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use ide_db::helpers::{ | 1 | use ide_db::helpers::{ |
2 | import_assets::{ImportAssets, ImportCandidate}, | 2 | import_assets::{ImportAssets, ImportCandidate}, |
3 | insert_use::{insert_use, ImportScope}, | 3 | insert_use::{insert_use, ImportScope}, |
4 | item_name, mod_path_to_ast, | 4 | mod_path_to_ast, |
5 | }; | 5 | }; |
6 | use syntax::{ast, AstNode, SyntaxNode}; | 6 | use syntax::{ast, AstNode, SyntaxNode}; |
7 | 7 | ||
@@ -90,17 +90,13 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
90 | } | 90 | } |
91 | 91 | ||
92 | let range = ctx.sema.original_range(&syntax_under_caret).range; | 92 | let range = ctx.sema.original_range(&syntax_under_caret).range; |
93 | let group = import_group_message(import_assets.import_candidate()); | 93 | let group_label = group_label(import_assets.import_candidate()); |
94 | let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; | 94 | let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; |
95 | for import in proposed_imports { | 95 | for import in proposed_imports { |
96 | let name = match item_name(ctx.db(), import.original_item) { | ||
97 | Some(name) => name, | ||
98 | None => continue, | ||
99 | }; | ||
100 | acc.add_group( | 96 | acc.add_group( |
101 | &group, | 97 | &group_label, |
102 | AssistId("auto_import", AssistKind::QuickFix), | 98 | AssistId("auto_import", AssistKind::QuickFix), |
103 | format!("Import `{}`", name), | 99 | format!("Import `{}`", import.import_path), |
104 | range, | 100 | range, |
105 | |builder| { | 101 | |builder| { |
106 | let rewriter = | 102 | let rewriter = |
@@ -126,7 +122,7 @@ pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets, | |||
126 | } | 122 | } |
127 | } | 123 | } |
128 | 124 | ||
129 | fn import_group_message(import_candidate: &ImportCandidate) -> GroupLabel { | 125 | fn group_label(import_candidate: &ImportCandidate) -> GroupLabel { |
130 | let name = match import_candidate { | 126 | let name = match import_candidate { |
131 | ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()), | 127 | ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()), |
132 | ImportCandidate::TraitAssocItem(candidate) => { | 128 | ImportCandidate::TraitAssocItem(candidate) => { |
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 272874ae3..30b23da6c 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs | |||
@@ -3,7 +3,7 @@ use std::iter; | |||
3 | use hir::AsAssocItem; | 3 | use hir::AsAssocItem; |
4 | use ide_db::helpers::{ | 4 | use ide_db::helpers::{ |
5 | import_assets::{ImportCandidate, LocatedImport}, | 5 | import_assets::{ImportCandidate, LocatedImport}, |
6 | item_name, mod_path_to_ast, | 6 | mod_path_to_ast, |
7 | }; | 7 | }; |
8 | use ide_db::RootDatabase; | 8 | use ide_db::RootDatabase; |
9 | use syntax::{ | 9 | use syntax::{ |
@@ -78,7 +78,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
78 | acc.add_group( | 78 | acc.add_group( |
79 | &group_label, | 79 | &group_label, |
80 | AssistId("qualify_path", AssistKind::QuickFix), | 80 | AssistId("qualify_path", AssistKind::QuickFix), |
81 | label(ctx.db(), candidate, &import), | 81 | label(candidate, &import), |
82 | range, | 82 | range, |
83 | |builder| { | 83 | |builder| { |
84 | qualify_candidate.qualify( | 84 | qualify_candidate.qualify( |
@@ -199,21 +199,17 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel { | |||
199 | GroupLabel(format!("Qualify {}", name)) | 199 | GroupLabel(format!("Qualify {}", name)) |
200 | } | 200 | } |
201 | 201 | ||
202 | fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String { | 202 | fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String { |
203 | let display_path = match item_name(db, import.original_item) { | ||
204 | Some(display_path) => display_path.to_string(), | ||
205 | None => "{unknown}".to_string(), | ||
206 | }; | ||
207 | match candidate { | 203 | match candidate { |
208 | ImportCandidate::Path(candidate) => { | 204 | ImportCandidate::Path(candidate) => { |
209 | if candidate.qualifier.is_some() { | 205 | if candidate.qualifier.is_some() { |
210 | format!("Qualify with `{}`", display_path) | 206 | format!("Qualify with `{}`", import.import_path) |
211 | } else { | 207 | } else { |
212 | format!("Qualify as `{}`", display_path) | 208 | format!("Qualify as `{}`", import.import_path) |
213 | } | 209 | } |
214 | } | 210 | } |
215 | ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", display_path), | 211 | ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path), |
216 | ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", display_path), | 212 | ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path), |
217 | } | 213 | } |
218 | } | 214 | } |
219 | 215 | ||