diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_snippet.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_snippet.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs index f731e9b9a..4bccfbfed 100644 --- a/crates/ra_ide/src/completion/complete_snippet.rs +++ b/crates/ra_ide/src/completion/complete_snippet.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use crate::completion::{ | 3 | use crate::completion::{ |
4 | completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind, | 4 | completion_config::SnippetCap, completion_item::Builder, CompletionContext, CompletionItem, |
5 | CompletionKind, Completions, | 5 | CompletionItemKind, CompletionKind, Completions, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | fn snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder { | 8 | fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { |
9 | CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label) | 9 | CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label) |
10 | .insert_snippet(snippet) | 10 | .insert_snippet(cap, snippet) |
11 | .kind(CompletionItemKind::Snippet) | 11 | .kind(CompletionItemKind::Snippet) |
12 | } | 12 | } |
13 | 13 | ||
@@ -15,17 +15,27 @@ pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte | |||
15 | if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { | 15 | if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { |
16 | return; | 16 | return; |
17 | } | 17 | } |
18 | let cap = match ctx.config.snippet_cap { | ||
19 | Some(it) => it, | ||
20 | None => return, | ||
21 | }; | ||
18 | 22 | ||
19 | snippet(ctx, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); | 23 | snippet(ctx, cap, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); |
20 | snippet(ctx, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); | 24 | snippet(ctx, cap, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); |
21 | } | 25 | } |
22 | 26 | ||
23 | pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { | 27 | pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { |
24 | if !ctx.is_new_item { | 28 | if !ctx.is_new_item { |
25 | return; | 29 | return; |
26 | } | 30 | } |
31 | let cap = match ctx.config.snippet_cap { | ||
32 | Some(it) => it, | ||
33 | None => return, | ||
34 | }; | ||
35 | |||
27 | snippet( | 36 | snippet( |
28 | ctx, | 37 | ctx, |
38 | cap, | ||
29 | "Test function", | 39 | "Test function", |
30 | "\ | 40 | "\ |
31 | #[test] | 41 | #[test] |
@@ -36,8 +46,8 @@ fn ${1:feature}() { | |||
36 | .lookup_by("tfn") | 46 | .lookup_by("tfn") |
37 | .add_to(acc); | 47 | .add_to(acc); |
38 | 48 | ||
39 | snippet(ctx, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}").add_to(acc); | 49 | snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}").add_to(acc); |
40 | snippet(ctx, "pub(crate)", "pub(crate) $0").add_to(acc); | 50 | snippet(ctx, cap, "pub(crate)", "pub(crate) $0").add_to(acc); |
41 | } | 51 | } |
42 | 52 | ||
43 | #[cfg(test)] | 53 | #[cfg(test)] |