diff options
Diffstat (limited to 'crates/ide/src/completion.rs')
-rw-r--r-- | crates/ide/src/completion.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/ide/src/completion.rs b/crates/ide/src/completion.rs index b0e35b2bd..69e875014 100644 --- a/crates/ide/src/completion.rs +++ b/crates/ide/src/completion.rs | |||
@@ -112,6 +112,11 @@ pub(crate) fn completions( | |||
112 | ) -> Option<Completions> { | 112 | ) -> Option<Completions> { |
113 | let ctx = CompletionContext::new(db, position, config)?; | 113 | let ctx = CompletionContext::new(db, position, config)?; |
114 | 114 | ||
115 | if ctx.no_completion_required() { | ||
116 | // No work required here. | ||
117 | return None; | ||
118 | } | ||
119 | |||
115 | let mut acc = Completions::default(); | 120 | let mut acc = Completions::default(); |
116 | complete_attribute::complete_attribute(&mut acc, &ctx); | 121 | complete_attribute::complete_attribute(&mut acc, &ctx); |
117 | complete_fn_param::complete_fn_param(&mut acc, &ctx); | 122 | complete_fn_param::complete_fn_param(&mut acc, &ctx); |
@@ -157,6 +162,23 @@ mod tests { | |||
157 | panic!("completion detail not found: {}", expected.detail) | 162 | panic!("completion detail not found: {}", expected.detail) |
158 | } | 163 | } |
159 | 164 | ||
165 | fn check_no_completion(ra_fixture: &str) { | ||
166 | let (analysis, position) = fixture::position(ra_fixture); | ||
167 | let config = CompletionConfig::default(); | ||
168 | analysis.completions(&config, position).unwrap(); | ||
169 | |||
170 | let completions: Option<Vec<String>> = analysis | ||
171 | .completions(&config, position) | ||
172 | .unwrap() | ||
173 | .and_then(|completions| if completions.is_empty() { None } else { Some(completions) }) | ||
174 | .map(|completions| { | ||
175 | completions.into_iter().map(|completion| format!("{:?}", completion)).collect() | ||
176 | }); | ||
177 | |||
178 | // `assert_eq` instead of `assert!(completions.is_none())` to get the list of completions if test will panic. | ||
179 | assert_eq!(completions, None, "Completions were generated, but weren't expected"); | ||
180 | } | ||
181 | |||
160 | #[test] | 182 | #[test] |
161 | fn test_completion_detail_from_macro_generated_struct_fn_doc_attr() { | 183 | fn test_completion_detail_from_macro_generated_struct_fn_doc_attr() { |
162 | check_detail_and_documentation( | 184 | check_detail_and_documentation( |
@@ -208,4 +230,31 @@ mod tests { | |||
208 | DetailAndDocumentation { detail: "fn foo(&self)", documentation: " Do the foo" }, | 230 | DetailAndDocumentation { detail: "fn foo(&self)", documentation: " Do the foo" }, |
209 | ); | 231 | ); |
210 | } | 232 | } |
233 | |||
234 | #[test] | ||
235 | fn test_no_completions_required() { | ||
236 | // There must be no hint for 'in' keyword. | ||
237 | check_no_completion( | ||
238 | r#" | ||
239 | fn foo() { | ||
240 | for i i<|> | ||
241 | } | ||
242 | "#, | ||
243 | ); | ||
244 | // After 'in' keyword hints may be spawned. | ||
245 | check_detail_and_documentation( | ||
246 | r#" | ||
247 | /// Do the foo | ||
248 | fn foo() -> &'static str { "foo" } | ||
249 | |||
250 | fn bar() { | ||
251 | for c in fo<|> | ||
252 | } | ||
253 | "#, | ||
254 | DetailAndDocumentation { | ||
255 | detail: "fn foo() -> &'static str", | ||
256 | documentation: "Do the foo", | ||
257 | }, | ||
258 | ); | ||
259 | } | ||
211 | } | 260 | } |