aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/completion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/completion.rs')
-rw-r--r--crates/ide/src/completion.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ide/src/completion.rs b/crates/ide/src/completion.rs
index b0e35b2bd..570091ba3 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,15 @@ 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 check_no_completion(
237 r#"
238 fn foo() {
239 for i i<|>
240 }
241 "#,
242 )
243 }
211} 244}