From 79293d2593ba658243d0f2edf18cd283fa40447a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Sep 2018 17:24:18 +0300 Subject: [PATCH] eprintln --- crates/ra_editor/src/completion.rs | 44 +++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/ra_editor/src/completion.rs b/crates/ra_editor/src/completion.rs index 5000b32a05..ff9de20d38 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 CompletionItem { } } +fn complete_expr_snippets(acc: &mut Vec) { + acc.push(CompletionItem { + label: "pd".to_string(), + lookup: None, + snippet: Some("eprintln!(\"$0 = {:?}\", $0);".to_string()), + } + ); + acc.push(CompletionItem { + label: "ppd".to_string(), + lookup: None, + snippet: Some("eprintln!(\"$0 = {:#?}\", $0);".to_string()), + } + ); +} + fn complete_fn(name_ref: ast::NameRef, scopes: &FnScopes, acc: &mut Vec) { let mut shadowed = HashSet::new(); acc.extend( @@ -363,7 +379,9 @@ mod tests { CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); } #[test] @@ -380,7 +398,9 @@ mod tests { CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, CompletionItem { label: "else", lookup: None, snippet: Some("else {$0}") }, CompletionItem { label: "else if", lookup: None, snippet: Some("else if $0 {}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); } #[test] @@ -394,7 +414,9 @@ mod tests { CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return $0;") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return $0;") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); check_snippet_completion(r" fn quux() { <|> @@ -404,7 +426,9 @@ mod tests { CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return;") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return;") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); } #[test] @@ -419,7 +443,9 @@ mod tests { CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); } #[test] @@ -434,7 +460,9 @@ mod tests { CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, CompletionItem { label: "continue", lookup: None, snippet: Some("continue") }, CompletionItem { label: "break", lookup: None, snippet: Some("break") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); check_snippet_completion(r" fn quux() -> i32 { loop { || { <|> } } @@ -443,7 +471,9 @@ mod tests { CompletionItem { label: "match", lookup: None, snippet: Some("match $0 {}") }, CompletionItem { label: "while", lookup: None, snippet: Some("while $0 {}") }, CompletionItem { label: "loop", lookup: None, snippet: Some("loop {$0}") }, - CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }]"#); + CompletionItem { label: "return", lookup: None, snippet: Some("return $0") }, + CompletionItem { label: "pd", lookup: None, snippet: Some("eprintln!(\"$0 = {:?}\", $0);") }, + CompletionItem { label: "ppd", lookup: None, snippet: Some("eprintln!(\"$0 = {:#?}\", $0);") }]"#); } #[test]