diff options
author | Kirill Bulatov <[email protected]> | 2021-03-02 23:26:53 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:20 +0000 |
commit | 33c83e72b9b48177a6171fd06a26676679963a4d (patch) | |
tree | b787206319b2cf0050e4ce7c89ad4365b9a43c11 /crates/ide_assists/src/handlers/qualify_path.rs | |
parent | 4d4ac1d4fa0aba107a27d3fd2d209304dfe69b9f (diff) |
Work towards better import labels
Diffstat (limited to 'crates/ide_assists/src/handlers/qualify_path.rs')
-rw-r--r-- | crates/ide_assists/src/handlers/qualify_path.rs | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 261178448..407ba47be 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs | |||
@@ -2,7 +2,7 @@ use std::iter; | |||
2 | 2 | ||
3 | use hir::AsAssocItem; | 3 | use hir::AsAssocItem; |
4 | use ide_db::helpers::{ | 4 | use ide_db::helpers::{ |
5 | import_assets::{ImportCandidate, Qualifier}, | 5 | import_assets::{ImportCandidate, LocatedImport, Qualifier}, |
6 | mod_path_to_ast, | 6 | mod_path_to_ast, |
7 | }; | 7 | }; |
8 | use ide_db::RootDatabase; | 8 | use ide_db::RootDatabase; |
@@ -78,13 +78,13 @@ 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(candidate, import.display_path()), | 81 | label(ctx.db(), candidate, &import), |
82 | range, | 82 | range, |
83 | |builder| { | 83 | |builder| { |
84 | qualify_candidate.qualify( | 84 | qualify_candidate.qualify( |
85 | |replace_with: String| builder.replace(range, replace_with), | 85 | |replace_with: String| builder.replace(range, replace_with), |
86 | import.import_path(), | 86 | &import.import_path, |
87 | import.item_to_import(), | 87 | import.item_to_import, |
88 | ) | 88 | ) |
89 | }, | 89 | }, |
90 | ); | 90 | ); |
@@ -197,17 +197,21 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel { | |||
197 | GroupLabel(format!("Qualify {}", name)) | 197 | GroupLabel(format!("Qualify {}", name)) |
198 | } | 198 | } |
199 | 199 | ||
200 | fn label(candidate: &ImportCandidate, import: &hir::ModPath) -> String { | 200 | fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String { |
201 | let display_path = match import.original_item_name(db) { | ||
202 | Some(display_path) => display_path.to_string(), | ||
203 | None => "{unknown}".to_string(), | ||
204 | }; | ||
201 | match candidate { | 205 | match candidate { |
202 | ImportCandidate::Path(candidate) => { | 206 | ImportCandidate::Path(candidate) => { |
203 | if !matches!(candidate.qualifier, Qualifier::Absent) { | 207 | if !matches!(candidate.qualifier, Qualifier::Absent) { |
204 | format!("Qualify with `{}`", &import) | 208 | format!("Qualify with `{}`", display_path) |
205 | } else { | 209 | } else { |
206 | format!("Qualify as `{}`", &import) | 210 | format!("Qualify as `{}`", display_path) |
207 | } | 211 | } |
208 | } | 212 | } |
209 | ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", &import), | 213 | ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", display_path), |
210 | ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", &import), | 214 | ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", display_path), |
211 | } | 215 | } |
212 | } | 216 | } |
213 | 217 | ||