diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-21 23:28:47 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-21 23:28:47 +0000 |
commit | 4e4ca27eabac6a9c97dc07baf9a067efdfc63384 (patch) | |
tree | 83c75bdefa688a220054bf671ffe1692887d6dd4 /crates/ra_analysis/src/completion/complete_snippet.rs | |
parent | e4d0930d9c6478f7aa069401fb7e28ab7c80fd14 (diff) | |
parent | ea763c73b8d89edbf716805c62cf31b00e2e1a4f (diff) |
Merge #319
319: Completion icons r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/completion/complete_snippet.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_snippet.rs | 37 |
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 @@ | |||
1 | use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}; | 1 | use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; |
2 | |||
3 | fn snippet(label: &str, snippet: &str) -> Builder { | ||
4 | CompletionItem::new(CompletionKind::Snippet, label) | ||
5 | .snippet(snippet) | ||
6 | .kind(CompletionItemKind::Snippet) | ||
7 | } | ||
2 | 8 | ||
3 | pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(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 | ||
17 | pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { | 17 | pub(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] |
26 | fn ${1:feature}() { | 25 | fn ${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)] |