aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-18 20:36:52 +0000
committerLukas Wirth <[email protected]>2021-03-18 20:36:52 +0000
commit34464ede3f57cbab4d6d1a67f36252cc22c02765 (patch)
tree2c0ce285ca796ef3e92a6bfaa487859075be3c7a /crates
parent816bc7389516dda1eb4821f2ac4d5993cd5611dd (diff)
Fix associated items not being appended to paths in import_assets
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_assists/src/handlers/qualify_path.rs37
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs6
2 files changed, 40 insertions, 3 deletions
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs
index 30b23da6c..40571e52b 100644
--- a/crates/ide_assists/src/handlers/qualify_path.rs
+++ b/crates/ide_assists/src/handlers/qualify_path.rs
@@ -208,8 +208,10 @@ fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
208 format!("Qualify as `{}`", import.import_path) 208 format!("Qualify as `{}`", import.import_path)
209 } 209 }
210 } 210 }
211 ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path), 211 ImportCandidate::TraitAssocItem(_) => {
212 ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path), 212 format!("Qualify with `{}`", import.import_path)
213 }
214 ImportCandidate::TraitMethod(_) => format!("Qualify with `{}`", import.import_path),
213 } 215 }
214} 216}
215 217
@@ -544,6 +546,37 @@ fn main() {
544 } 546 }
545 547
546 #[test] 548 #[test]
549 fn associated_struct_const_unqualified() {
550 check_assist(
551 qualify_path,
552 r"
553 mod test_mod {
554 pub struct TestStruct {}
555 impl TestStruct {
556 const TEST_CONST: u8 = 42;
557 }
558 }
559
560 fn main() {
561 TEST_CONST$0
562 }
563 ",
564 r"
565 mod test_mod {
566 pub struct TestStruct {}
567 impl TestStruct {
568 const TEST_CONST: u8 = 42;
569 }
570 }
571
572 fn main() {
573 test_mod::TestStruct::TEST_CONST
574 }
575 ",
576 );
577 }
578
579 #[test]
547 fn associated_trait_function() { 580 fn associated_trait_function() {
548 check_assist( 581 check_assist(
549 qualify_path, 582 qualify_path,
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs
index e03ccd351..7c8844e95 100644
--- a/crates/ide_db/src/helpers/import_assets.rs
+++ b/crates/ide_db/src/helpers/import_assets.rs
@@ -304,7 +304,11 @@ fn path_applicable_imports(
304 return items_with_candidate_name 304 return items_with_candidate_name
305 .into_iter() 305 .into_iter()
306 .filter_map(|item| { 306 .filter_map(|item| {
307 Some(LocatedImport::new(mod_path(item)?, item, item, mod_path(item))) 307 let mut mod_path = mod_path(item)?;
308 if let Some(assoc_item) = item_as_assoc(db, item) {
309 mod_path.push_segment(assoc_item.name(db)?);
310 }
311 Some(LocatedImport::new(mod_path.clone(), item, item, Some(mod_path)))
308 }) 312 })
309 .collect(); 313 .collect();
310 } 314 }