aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-02-24 23:53:59 +0000
committerKirill Bulatov <[email protected]>2021-03-08 21:59:20 +0000
commitd386481fac65e988fa4d13c1bc8d4ddb2bc490c6 (patch)
tree8557145c14606093a4ce75938e9b884ea4f01a90 /crates/ide_completion
parent582cee2cdf5355b681f14bbb33bd5c431c284d87 (diff)
Fix some tests
Diffstat (limited to 'crates/ide_completion')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs65
-rw-r--r--crates/ide_completion/src/render.rs7
2 files changed, 65 insertions, 7 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 8ff76688e..e33fc4b78 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -97,7 +97,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
97 .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) 97 .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
98 .into_iter() 98 .into_iter()
99 .map(|import| { 99 .map(|import| {
100 let proposed_def = match import.item_to_import() { 100 let proposed_def = match import.item_to_display() {
101 hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), 101 hir::ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()),
102 hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), 102 hir::ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()),
103 hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), 103 hir::ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()),
@@ -809,7 +809,7 @@ fn main() {
809 #[test] 809 #[test]
810 fn unresolved_assoc_item_container() { 810 fn unresolved_assoc_item_container() {
811 check_edit( 811 check_edit(
812 "Item", 812 "TEST_ASSOC",
813 r#" 813 r#"
814mod foo { 814mod foo {
815 pub struct Item; 815 pub struct Item;
@@ -820,7 +820,7 @@ mod foo {
820} 820}
821 821
822fn main() { 822fn main() {
823 Item::TEST_A$0; 823 Item::TEST_A$0
824} 824}
825"#, 825"#,
826 r#" 826 r#"
@@ -844,7 +844,7 @@ fn main() {
844 #[test] 844 #[test]
845 fn unresolved_assoc_item_container_with_path() { 845 fn unresolved_assoc_item_container_with_path() {
846 check_edit( 846 check_edit(
847 "Item", 847 "TEST_ASSOC",
848 r#" 848 r#"
849mod foo { 849mod foo {
850 pub mod bar { 850 pub mod bar {
@@ -857,7 +857,7 @@ mod foo {
857} 857}
858 858
859fn main() { 859fn main() {
860 bar::Item::TEST_A$0; 860 bar::Item::TEST_A$0
861} 861}
862"#, 862"#,
863 r#" 863 r#"
@@ -879,4 +879,59 @@ fn main() {
879"#, 879"#,
880 ); 880 );
881 } 881 }
882
883 #[test]
884 fn unresolved_assoc_item_container_and_trait_with_path() {
885 check_edit(
886 "TEST_ASSOC",
887 r#"
888mod foo {
889 pub mod bar {
890 pub trait SomeTrait {
891 const TEST_ASSOC: usize;
892 }
893 }
894
895 pub mod baz {
896 use super::bar::SomeTrait;
897
898 pub struct Item;
899
900 impl SomeTrait for Item {
901 const TEST_ASSOC: usize = 3;
902 }
903 }
904}
905
906fn main() {
907 baz::Item::TEST_A$0
908}
909"#,
910 r#"
911use foo::{bar::SomeTrait, baz};
912
913mod foo {
914 pub mod bar {
915 pub trait SomeTrait {
916 const TEST_ASSOC: usize;
917 }
918 }
919
920 pub mod baz {
921 use super::bar::SomeTrait;
922
923 pub struct Item;
924
925 impl SomeTrait for Item {
926 const TEST_ASSOC: usize = 3;
927 }
928 }
929}
930
931fn main() {
932 baz::Item::TEST_ASSOC
933}
934"#,
935 );
936 }
882} 937}
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index df26e7642..4bddc3957 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -13,7 +13,10 @@ mod builder_ext;
13use hir::{ 13use hir::{
14 AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type, 14 AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
15}; 15};
16use ide_db::{helpers::SnippetCap, RootDatabase, SymbolKind}; 16use ide_db::{
17 helpers::{item_name, SnippetCap},
18 RootDatabase, SymbolKind,
19};
17use syntax::TextRange; 20use syntax::TextRange;
18 21
19use crate::{ 22use crate::{
@@ -56,7 +59,7 @@ pub(crate) fn render_resolution_with_import<'a>(
56 ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(), 59 ScopeDef::ModuleDef(ModuleDef::Function(f)) => f.name(ctx.completion.db).to_string(),
57 ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(), 60 ScopeDef::ModuleDef(ModuleDef::Const(c)) => c.name(ctx.completion.db)?.to_string(),
58 ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(), 61 ScopeDef::ModuleDef(ModuleDef::TypeAlias(t)) => t.name(ctx.completion.db).to_string(),
59 _ => import_edit.import.display_path().segments().last()?.to_string(), 62 _ => item_name(ctx.db(), import_edit.import.item_to_display())?.to_string(),
60 }; 63 };
61 Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| { 64 Render::new(ctx).render_resolution(local_name, Some(import_edit), resolution).map(|mut item| {
62 item.completion_kind = CompletionKind::Magic; 65 item.completion_kind = CompletionKind::Magic;