aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/complete_snippet.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/complete_snippet.rs')
-rw-r--r--crates/ra_analysis/src/completion/complete_snippet.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs
index ccd68832b..fb9da0a4f 100644
--- a/crates/ra_analysis/src/completion/complete_snippet.rs
+++ b/crates/ra_analysis/src/completion/complete_snippet.rs
@@ -1,38 +1,35 @@
1use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}; 1use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder};
2
3fn snippet(label: &str, snippet: &str) -> Builder {
4 CompletionItem::new(CompletionKind::Snippet, label)
5 .snippet(snippet)
6 .kind(CompletionItemKind::Snippet)
7}
2 8
3pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { 9pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
4 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { 10 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) {
5 return; 11 return;
6 } 12 }
7 CompletionItem::new("pd") 13 snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc);
8 .snippet("eprintln!(\"$0 = {:?}\", $0);") 14 snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc);
9 .kind(Snippet)
10 .add_to(acc);
11 CompletionItem::new("ppd")
12 .snippet("eprintln!(\"$0 = {:#?}\", $0);")
13 .kind(Snippet)
14 .add_to(acc);
15} 15}
16 16
17pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { 17pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
18 if !ctx.is_new_item { 18 if !ctx.is_new_item {
19 return; 19 return;
20 } 20 }
21 CompletionItem::new("Test function") 21 snippet(
22 .lookup_by("tfn") 22 "Test function",
23 .snippet( 23 "\
24 "\
25#[test] 24#[test]
26fn ${1:feature}() { 25fn ${1:feature}() {
27 $0 26 $0
28}", 27}",
29 ) 28 )
30 .kind(Snippet) 29 .lookup_by("tfn")
31 .add_to(acc); 30 .add_to(acc);
32 CompletionItem::new("pub(crate)") 31
33 .snippet("pub(crate) $0") 32 snippet("pub(crate)", "pub(crate) $0").add_to(acc);
34 .kind(Snippet)
35 .add_to(acc);
36} 33}
37 34
38#[cfg(test)] 35#[cfg(test)]