diff options
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 75 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/postfix/format_like.rs | 2 |
2 files changed, 75 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 9ace13e41..9d5b61562 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -114,6 +114,8 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
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() | 116 | || ctx.record_lit_syntax.is_some() |
117 | || ctx.has_trait_parent | ||
118 | || ctx.has_impl_parent | ||
117 | { | 119 | { |
118 | return None; | 120 | return None; |
119 | } | 121 | } |
@@ -130,7 +132,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
130 | 132 | ||
131 | let user_input_lowercased = potential_import_name.to_lowercase(); | 133 | let user_input_lowercased = potential_import_name.to_lowercase(); |
132 | let import_assets = import_assets(ctx, potential_import_name)?; | 134 | let import_assets = import_assets(ctx, potential_import_name)?; |
133 | let import_scope = ImportScope::find_insert_use_container( | 135 | let import_scope = ImportScope::find_insert_use_container_with_macros( |
134 | position_for_import(ctx, Some(import_assets.import_candidate()))?, | 136 | position_for_import(ctx, Some(import_assets.import_candidate()))?, |
135 | &ctx.sema, | 137 | &ctx.sema, |
136 | )?; | 138 | )?; |
@@ -1077,4 +1079,75 @@ fn main() { | |||
1077 | "#]], | 1079 | "#]], |
1078 | ); | 1080 | ); |
1079 | } | 1081 | } |
1082 | |||
1083 | #[test] | ||
1084 | fn no_flyimports_in_traits_and_impl_declarations() { | ||
1085 | check( | ||
1086 | r#" | ||
1087 | mod m { | ||
1088 | pub fn some_fn() -> i32 { | ||
1089 | 42 | ||
1090 | } | ||
1091 | } | ||
1092 | trait Foo { | ||
1093 | som$0 | ||
1094 | } | ||
1095 | "#, | ||
1096 | expect![[r#""#]], | ||
1097 | ); | ||
1098 | |||
1099 | check( | ||
1100 | r#" | ||
1101 | mod m { | ||
1102 | pub fn some_fn() -> i32 { | ||
1103 | 42 | ||
1104 | } | ||
1105 | } | ||
1106 | struct Foo; | ||
1107 | impl Foo { | ||
1108 | som$0 | ||
1109 | } | ||
1110 | "#, | ||
1111 | expect![[r#""#]], | ||
1112 | ); | ||
1113 | |||
1114 | check( | ||
1115 | r#" | ||
1116 | mod m { | ||
1117 | pub fn some_fn() -> i32 { | ||
1118 | 42 | ||
1119 | } | ||
1120 | } | ||
1121 | struct Foo; | ||
1122 | trait Bar {} | ||
1123 | impl 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#" | ||
1135 | mod baz { | ||
1136 | pub trait DefDatabase { | ||
1137 | fn method1(&self); | ||
1138 | } | ||
1139 | pub trait HirDatabase: DefDatabase { | ||
1140 | fn method2(&self); | ||
1141 | } | ||
1142 | } | ||
1143 | |||
1144 | mod bar { | ||
1145 | fn test(db: &dyn crate::baz::HirDatabase) { | ||
1146 | db.metho$0 | ||
1147 | } | ||
1148 | } | ||
1149 | "#, | ||
1150 | expect![[r#""#]], | ||
1151 | ); | ||
1152 | } | ||
1080 | } | 1153 | } |
diff --git a/crates/ide_completion/src/completions/postfix/format_like.rs b/crates/ide_completion/src/completions/postfix/format_like.rs index e86ffa8f8..0dcb3e898 100644 --- a/crates/ide_completion/src/completions/postfix/format_like.rs +++ b/crates/ide_completion/src/completions/postfix/format_like.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | // Feature: Format String Completion. | 1 | // Feature: Format String Completion |
2 | // | 2 | // |
3 | // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`. | 3 | // `"Result {result} is {2 + 2}"` is expanded to the `"Result {} is {}", result, 2 + 2`. |
4 | // | 4 | // |