aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_editor/src/completion.rs44
1 files changed, 37 insertions, 7 deletions
diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs
index 5000b32a0..ff9de20d3 100644
--- a/crates/ra_editor/src/completion.rs
+++ b/crates/ra_editor/src/completion.rs
@@ -82,6 +82,7 @@ fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<Completi
82 if let Some(fn_def) = ast::FnDef::cast(node) { 82 if let Some(fn_def) = ast::FnDef::cast(node) {
83 visited_fn = true; 83 visited_fn = true;
84 complete_expr_keywords(&file, fn_def, name_ref, acc); 84 complete_expr_keywords(&file, fn_def, name_ref, acc);
85 complete_expr_snippets(acc);
85 let scopes = FnScopes::new(fn_def); 86 let scopes = FnScopes::new(fn_def);
86 complete_fn(name_ref, &scopes, acc); 87 complete_fn(name_ref, &scopes, acc);
87 } 88 }
@@ -201,6 +202,21 @@ fn keyword(kw: &str, snip: &str) -> CompletionItem {
201 } 202 }
202} 203}
203 204
205fn complete_expr_snippets(acc: &mut Vec<CompletionItem>) {
206 acc.push(CompletionItem {
207 label: "pd".to_string(),
208 lookup: None,
209 snippet: Some("eprintln!(\"$0 = {:?}\", $0);".to_string()),
210 }
211 );
212 acc.push(CompletionItem {
213 label: "ppd".to_string(),
214 lookup: None,
215 snippet: Some("eprintln!(\"$0 = {:#?}\", $0);".to_string()),
216 }
217 );
218}
219
204fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) { 220fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec<CompletionItem>) {
205 let mut shadowed = HashSet::new(); 221 let mut shadowed = HashSet::new();
206 acc.extend( 222 acc.extend(
@@ -363,7 +379,9 @@ mod tests {
363 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, 379 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") },
364 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, 380 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") },
365 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 381 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
366 CompletionItem { label: "return", lookup: None, snippet: Some("return") }]"#); 382 CompletionItem { label: "return", lookup: None, snippet: Some("return") },
383 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
384 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
367 } 385 }
368 386
369 #[test] 387 #[test]
@@ -380,7 +398,9 @@ mod tests {
380 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 398 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
381 CompletionItem { label: "else", lookup: None, snippet: Some("else {$0}") }, 399 CompletionItem { label: "else", lookup: None, snippet: Some("else {$0}") },
382 CompletionItem { label: "else if", lookup: None, snippet: Some("else if $0 {}") }, 400 CompletionItem { label: "else if", lookup: None, snippet: Some("else if $0 {}") },
383 CompletionItem { label: "return", lookup: None, snippet: Some("return") }]"#); 401 CompletionItem { label: "return", lookup: None, snippet: Some("return") },
402 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
403 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
384 } 404 }
385 405
386 #[test] 406 #[test]
@@ -394,7 +414,9 @@ mod tests {
394 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, 414 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") },
395 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, 415 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") },
396 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 416 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
397 CompletionItem { label: "return", lookup: None, snippet: Some("return $0;") }]"#); 417 CompletionItem { label: "return", lookup: None, snippet: Some("return $0;") },
418 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
419 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
398 check_snippet_completion(r" 420 check_snippet_completion(r"
399 fn quux() { 421 fn quux() {
400 <|> 422 <|>
@@ -404,7 +426,9 @@ mod tests {
404 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, 426 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") },
405 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, 427 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") },
406 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 428 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
407 CompletionItem { label: "return", lookup: None, snippet: Some("return;") }]"#); 429 CompletionItem { label: "return", lookup: None, snippet: Some("return;") },
430 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
431 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
408 } 432 }
409 433
410 #[test] 434 #[test]
@@ -419,7 +443,9 @@ mod tests {
419 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, 443 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") },
420 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, 444 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") },
421 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 445 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
422 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); 446 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") },
447 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
448 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
423 } 449 }
424 450
425 #[test] 451 #[test]
@@ -434,7 +460,9 @@ mod tests {
434 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 460 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
435 CompletionItem { label: "continue", lookup: None, snippet: Some("continue") }, 461 CompletionItem { label: "continue", lookup: None, snippet: Some("continue") },
436 CompletionItem { label: "break", lookup: None, snippet: Some("break") }, 462 CompletionItem { label: "break", lookup: None, snippet: Some("break") },
437 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); 463 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") },
464 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
465 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
438 check_snippet_completion(r" 466 check_snippet_completion(r"
439 fn quux() -> i32 { 467 fn quux() -> i32 {
440 loop { || { <|> } } 468 loop { || { <|> } }
@@ -443,7 +471,9 @@ mod tests {
443 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, 471 CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") },
444 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, 472 CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") },
445 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, 473 CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") },
446 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); 474 CompletionItem { label: "return", lookup: None, snippet: Some("return $0") },
475 CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") },
476 CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#);
447 } 477 }
448 478
449 #[test] 479 #[test]