aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r--crates/ide_assists/src/handlers/auto_import.rs8
-rw-r--r--crates/ide_assists/src/handlers/qualify_path.rs14
2 files changed, 12 insertions, 10 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs
index 5546c3a4e..7caee8df0 100644
--- a/crates/ide_assists/src/handlers/auto_import.rs
+++ b/crates/ide_assists/src/handlers/auto_import.rs
@@ -1,7 +1,7 @@
1use ide_db::helpers::{ 1use 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 mod_path_to_ast, 4 item_name, mod_path_to_ast,
5}; 5};
6use syntax::{ast, AstNode, SyntaxNode}; 6use syntax::{ast, AstNode, SyntaxNode};
7 7
@@ -93,7 +93,7 @@ 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()) { 96 let name = match item_name(ctx.db(), import.original_item) {
97 Some(name) => name, 97 Some(name) => name,
98 None => continue, 98 None => continue,
99 }; 99 };
@@ -130,10 +130,10 @@ fn import_group_message(import_candidate: &ImportCandidate) -> GroupLabel {
130 let name = match import_candidate { 130 let name = match import_candidate {
131 ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()), 131 ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()),
132 ImportCandidate::TraitAssocItem(candidate) => { 132 ImportCandidate::TraitAssocItem(candidate) => {
133 format!("Import a trait for item {}", candidate.name.text()) 133 format!("Import a trait for item {}", candidate.assoc_item_name.text())
134 } 134 }
135 ImportCandidate::TraitMethod(candidate) => { 135 ImportCandidate::TraitMethod(candidate) => {
136 format!("Import a trait for method {}", candidate.name.text()) 136 format!("Import a trait for method {}", candidate.assoc_item_name.text())
137 } 137 }
138 }; 138 };
139 GroupLabel(name) 139 GroupLabel(name)
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs
index b36dd3823..272874ae3 100644
--- a/crates/ide_assists/src/handlers/qualify_path.rs
+++ b/crates/ide_assists/src/handlers/qualify_path.rs
@@ -2,8 +2,8 @@ use std::iter;
2 2
3use hir::AsAssocItem; 3use hir::AsAssocItem;
4use ide_db::helpers::{ 4use ide_db::helpers::{
5 import_assets::{ImportCandidate, LocatedImport, Qualifier}, 5 import_assets::{ImportCandidate, LocatedImport},
6 mod_path_to_ast, 6 item_name, mod_path_to_ast,
7}; 7};
8use ide_db::RootDatabase; 8use ide_db::RootDatabase;
9use syntax::{ 9use syntax::{
@@ -48,7 +48,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
48 48
49 let qualify_candidate = match candidate { 49 let qualify_candidate = match candidate {
50 ImportCandidate::Path(candidate) => { 50 ImportCandidate::Path(candidate) => {
51 if !matches!(candidate.qualifier, Qualifier::Absent) { 51 if candidate.qualifier.is_some() {
52 cov_mark::hit!(qualify_path_qualifier_start); 52 cov_mark::hit!(qualify_path_qualifier_start);
53 let path = ast::Path::cast(syntax_under_caret)?; 53 let path = ast::Path::cast(syntax_under_caret)?;
54 let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?); 54 let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?);
@@ -191,20 +191,22 @@ fn item_as_trait(db: &RootDatabase, item: hir::ItemInNs) -> Option<hir::Trait> {
191fn group_label(candidate: &ImportCandidate) -> GroupLabel { 191fn group_label(candidate: &ImportCandidate) -> GroupLabel {
192 let name = match candidate { 192 let name = match candidate {
193 ImportCandidate::Path(it) => &it.name, 193 ImportCandidate::Path(it) => &it.name,
194 ImportCandidate::TraitAssocItem(it) | ImportCandidate::TraitMethod(it) => &it.name, 194 ImportCandidate::TraitAssocItem(it) | ImportCandidate::TraitMethod(it) => {
195 &it.assoc_item_name
196 }
195 } 197 }
196 .text(); 198 .text();
197 GroupLabel(format!("Qualify {}", name)) 199 GroupLabel(format!("Qualify {}", name))
198} 200}
199 201
200fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String { 202fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String {
201 let display_path = match import.original_item_name(db) { 203 let display_path = match item_name(db, import.original_item) {
202 Some(display_path) => display_path.to_string(), 204 Some(display_path) => display_path.to_string(),
203 None => "{unknown}".to_string(), 205 None => "{unknown}".to_string(),
204 }; 206 };
205 match candidate { 207 match candidate {
206 ImportCandidate::Path(candidate) => { 208 ImportCandidate::Path(candidate) => {
207 if !matches!(candidate.qualifier, Qualifier::Absent) { 209 if candidate.qualifier.is_some() {
208 format!("Qualify with `{}`", display_path) 210 format!("Qualify with `{}`", display_path)
209 } else { 211 } else {
210 format!("Qualify as `{}`", display_path) 212 format!("Qualify as `{}`", display_path)