aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions/flyimport.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/completions/flyimport.rs')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs116
1 files changed, 116 insertions, 0 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 1ad017198..8e211ae1e 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -113,6 +113,9 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
113 if ctx.use_item_syntax.is_some() 113 if ctx.use_item_syntax.is_some()
114 || ctx.attribute_under_caret.is_some() 114 || ctx.attribute_under_caret.is_some()
115 || ctx.mod_declaration_under_caret.is_some() 115 || ctx.mod_declaration_under_caret.is_some()
116 || ctx.record_lit_syntax.is_some()
117 || ctx.has_trait_parent
118 || ctx.has_impl_parent
116 { 119 {
117 return None; 120 return None;
118 } 121 }
@@ -1034,4 +1037,117 @@ fn main() {
1034 expect![[]], 1037 expect![[]],
1035 ); 1038 );
1036 } 1039 }
1040
1041 #[test]
1042 fn no_fuzzy_during_fields_of_record_lit_syntax() {
1043 check(
1044 r#"
1045mod m {
1046 pub fn some_fn() -> i32 {
1047 42
1048 }
1049}
1050struct Foo {
1051 some_field: i32,
1052}
1053fn main() {
1054 let _ = Foo { so$0 };
1055}
1056"#,
1057 expect![[]],
1058 );
1059 }
1060
1061 #[test]
1062 fn fuzzy_after_fields_of_record_lit_syntax() {
1063 check(
1064 r#"
1065mod m {
1066 pub fn some_fn() -> i32 {
1067 42
1068 }
1069}
1070struct Foo {
1071 some_field: i32,
1072}
1073fn main() {
1074 let _ = Foo { some_field: so$0 };
1075}
1076"#,
1077 expect![[r#"
1078 fn some_fn() (m::some_fn) fn() -> i32
1079 "#]],
1080 );
1081 }
1082
1083 #[test]
1084 fn no_flyimports_in_traits_and_impl_declarations() {
1085 check(
1086 r#"
1087mod m {
1088 pub fn some_fn() -> i32 {
1089 42
1090 }
1091}
1092trait Foo {
1093 som$0
1094}
1095"#,
1096 expect![[r#""#]],
1097 );
1098
1099 check(
1100 r#"
1101mod m {
1102 pub fn some_fn() -> i32 {
1103 42
1104 }
1105}
1106struct Foo;
1107impl Foo {
1108 som$0
1109}
1110"#,
1111 expect![[r#""#]],
1112 );
1113
1114 check(
1115 r#"
1116mod m {
1117 pub fn some_fn() -> i32 {
1118 42
1119 }
1120}
1121struct Foo;
1122trait Bar {}
1123impl Bar for Foo {
1124 som$0
1125}
1126"#,
1127 expect![[r#""#]],
1128 );
1129 }
1130
1131 #[test]
1132 fn no_inherent_candidates_proposed() {
1133 check(
1134 r#"
1135mod baz {
1136 pub trait DefDatabase {
1137 fn method1(&self);
1138 }
1139 pub trait HirDatabase: DefDatabase {
1140 fn method2(&self);
1141 }
1142}
1143
1144mod bar {
1145 fn test(db: &dyn crate::baz::HirDatabase) {
1146 db.metho$0
1147 }
1148}
1149 "#,
1150 expect![[r#""#]],
1151 );
1152 }
1037} 1153}