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