diff options
author | gfreezy <[email protected]> | 2019-01-19 14:02:50 +0000 |
---|---|---|
committer | gfreezy <[email protected]> | 2019-01-19 14:02:50 +0000 |
commit | d08e81cdd818dd3378c292767e15a38e6bbc6f6c (patch) | |
tree | e07b3363f21912ca7aaca4ae1dce482c0bcd6f85 /crates/ra_ide_api/src/completion/complete_snippet.rs | |
parent | fa43ef30f4f96fc8e4ea1f9c4492bcb07b3335ca (diff) |
refactor completions to use TextEdit instead of InsertText
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_snippet.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_snippet.rs | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs index a495751dd..fb94e3674 100644 --- a/crates/ra_ide_api/src/completion/complete_snippet.rs +++ b/crates/ra_ide_api/src/completion/complete_snippet.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; | 1 | use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; |
2 | 2 | ||
3 | fn snippet(label: &str, snippet: &str) -> Builder { | 3 | fn snippet<'a>(ctx: &'a CompletionContext<'a>, label: &str, snippet: &str) -> Builder<'a> { |
4 | CompletionItem::new(CompletionKind::Snippet, label) | 4 | CompletionItem::new(CompletionKind::Snippet, ctx, label) |
5 | .snippet(snippet) | 5 | .snippet(snippet) |
6 | .kind(CompletionItemKind::Snippet) | 6 | .kind(CompletionItemKind::Snippet) |
7 | } | 7 | } |
@@ -10,8 +10,8 @@ pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte | |||
10 | if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { | 10 | if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { |
11 | return; | 11 | return; |
12 | } | 12 | } |
13 | snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); | 13 | snippet(ctx, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); |
14 | snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); | 14 | snippet(ctx, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").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) { |
@@ -19,6 +19,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte | |||
19 | return; | 19 | return; |
20 | } | 20 | } |
21 | snippet( | 21 | snippet( |
22 | ctx, | ||
22 | "Test function", | 23 | "Test function", |
23 | "\ | 24 | "\ |
24 | #[test] | 25 | #[test] |
@@ -29,45 +30,33 @@ fn ${1:feature}() { | |||
29 | .lookup_by("tfn") | 30 | .lookup_by("tfn") |
30 | .add_to(acc); | 31 | .add_to(acc); |
31 | 32 | ||
32 | snippet("pub(crate)", "pub(crate) $0").add_to(acc); | 33 | snippet(ctx, "pub(crate)", "pub(crate) $0").add_to(acc); |
33 | } | 34 | } |
34 | 35 | ||
35 | #[cfg(test)] | 36 | #[cfg(test)] |
36 | mod tests { | 37 | mod tests { |
37 | use crate::completion::{CompletionKind, check_completion}; | 38 | use crate::completion::CompletionKind; |
38 | fn check_snippet_completion(code: &str, expected_completions: &str) { | 39 | use crate::completion::completion_item::check_completion; |
39 | check_completion(code, expected_completions, CompletionKind::Snippet); | 40 | |
41 | fn check_snippet_completion(name: &str, code: &str) { | ||
42 | check_completion(name, code, CompletionKind::Snippet); | ||
40 | } | 43 | } |
41 | 44 | ||
42 | #[test] | 45 | #[test] |
43 | fn completes_snippets_in_expressions() { | 46 | fn completes_snippets_in_expressions() { |
44 | check_snippet_completion( | 47 | check_snippet_completion("snippets_in_expressions", r"fn foo(x: i32) { <|> }"); |
45 | r"fn foo(x: i32) { <|> }", | ||
46 | r##" | ||
47 | pd "eprintln!(\"$0 = {:?}\", $0);" | ||
48 | ppd "eprintln!(\"$0 = {:#?}\", $0);" | ||
49 | "##, | ||
50 | ); | ||
51 | } | 48 | } |
52 | 49 | ||
53 | #[test] | 50 | #[test] |
54 | fn completes_snippets_in_items() { | 51 | fn completes_snippets_in_items() { |
55 | // check_snippet_completion(r" | ||
56 | // <|> | ||
57 | // ", | ||
58 | // r##"[CompletionItem { label: "Test function", lookup: None, snippet: Some("#[test]\nfn test_${1:feature}() {\n$0\n}"##, | ||
59 | // ); | ||
60 | check_snippet_completion( | 52 | check_snippet_completion( |
53 | "snippets_in_items", | ||
61 | r" | 54 | r" |
62 | #[cfg(test)] | 55 | #[cfg(test)] |
63 | mod tests { | 56 | mod tests { |
64 | <|> | 57 | <|> |
65 | } | 58 | } |
66 | ", | 59 | ", |
67 | r##" | ||
68 | tfn "Test function" "#[test]\nfn ${1:feature}() {\n $0\n}" | ||
69 | pub(crate) "pub(crate) $0" | ||
70 | "##, | ||
71 | ); | 60 | ); |
72 | } | 61 | } |
73 | } | 62 | } |