diff options
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r-- | crates/ide_assists/src/handlers/auto_import.rs | 13 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/qualify_path.rs | 22 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | 10 |
3 files changed, 26 insertions, 19 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 182547589..f3c969eee 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -93,17 +93,18 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
93 | let group = import_group_message(import_assets.import_candidate()); | 93 | let group = import_group_message(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 import.original_item_name(ctx.db()) { | ||
97 | Some(name) => name, | ||
98 | None => continue, | ||
99 | }; | ||
96 | acc.add_group( | 100 | acc.add_group( |
97 | &group, | 101 | &group, |
98 | AssistId("auto_import", AssistKind::QuickFix), | 102 | AssistId("auto_import", AssistKind::QuickFix), |
99 | format!("Import `{}`", import.display_path()), | 103 | format!("Import `{}`", name), |
100 | range, | 104 | range, |
101 | |builder| { | 105 | |builder| { |
102 | let rewriter = insert_use( | 106 | let rewriter = |
103 | &scope, | 107 | insert_use(&scope, mod_path_to_ast(&import.import_path), ctx.config.insert_use); |
104 | mod_path_to_ast(import.import_path()), | ||
105 | ctx.config.insert_use, | ||
106 | ); | ||
107 | builder.rewrite(rewriter); | 108 | builder.rewrite(rewriter); |
108 | }, | 109 | }, |
109 | ); | 110 | ); |
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 | ||
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index c69bc5cac..93a03e8b2 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use hir::ModuleDef; | ||
1 | use ide_db::helpers::mod_path_to_ast; | 2 | use ide_db::helpers::mod_path_to_ast; |
2 | use ide_db::imports_locator; | 3 | use ide_db::items_locator; |
3 | use itertools::Itertools; | 4 | use itertools::Itertools; |
4 | use syntax::{ | 5 | use syntax::{ |
5 | ast::{self, make, AstNode, NameOwner}, | 6 | ast::{self, make, AstNode, NameOwner}, |
@@ -64,13 +65,14 @@ pub(crate) fn replace_derive_with_manual_impl( | |||
64 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; | 65 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; |
65 | let current_crate = current_module.krate(); | 66 | let current_crate = current_module.krate(); |
66 | 67 | ||
67 | let found_traits = imports_locator::find_exact_imports( | 68 | let found_traits = items_locator::with_for_exact_name( |
68 | &ctx.sema, | 69 | &ctx.sema, |
69 | current_crate, | 70 | current_crate, |
70 | trait_token.text().to_string(), | 71 | trait_token.text().to_string(), |
71 | ) | 72 | ) |
72 | .filter_map(|candidate: either::Either<hir::ModuleDef, hir::MacroDef>| match candidate { | 73 | .into_iter() |
73 | either::Either::Left(hir::ModuleDef::Trait(trait_)) => Some(trait_), | 74 | .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { |
75 | ModuleDef::Trait(trait_) => Some(trait_), | ||
74 | _ => None, | 76 | _ => None, |
75 | }) | 77 | }) |
76 | .flat_map(|trait_| { | 78 | .flat_map(|trait_| { |