From 7543b06d301024d10b803f4c2bc269af9d481296 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 11 Aug 2020 22:33:17 +0300 Subject: Display snippet in the completion label --- crates/ra_ide/src/completion/complete_snippet.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide/src/completion/complete_snippet.rs') diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs index 28d8f7876..4368e4eec 100644 --- a/crates/ra_ide/src/completion/complete_snippet.rs +++ b/crates/ra_ide/src/completion/complete_snippet.rs @@ -36,7 +36,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte snippet( ctx, cap, - "Test module", + "tmod (Test module)", "\ #[cfg(test)] mod tests { @@ -54,7 +54,7 @@ mod tests { snippet( ctx, cap, - "Test function", + "tfn (Test function)", "\ #[test] fn ${1:feature}() { @@ -106,10 +106,10 @@ mod tests { } "#, expect![[r#" - sn Test function - sn Test module sn macro_rules sn pub(crate) + sn tfn (Test function) + sn tmod (Test module) "#]], ) } -- cgit v1.2.3 From 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 17:42:52 +0200 Subject: Rename ra_ide -> ide --- crates/ra_ide/src/completion/complete_snippet.rs | 116 ----------------------- 1 file changed, 116 deletions(-) delete mode 100644 crates/ra_ide/src/completion/complete_snippet.rs (limited to 'crates/ra_ide/src/completion/complete_snippet.rs') diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs deleted file mode 100644 index 4368e4eec..000000000 --- a/crates/ra_ide/src/completion/complete_snippet.rs +++ /dev/null @@ -1,116 +0,0 @@ -//! FIXME: write short doc here - -use crate::completion::{ - completion_config::SnippetCap, completion_item::Builder, CompletionContext, CompletionItem, - CompletionItemKind, CompletionKind, Completions, -}; - -fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str) -> Builder { - CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label) - .insert_snippet(cap, snippet) - .kind(CompletionItemKind::Snippet) -} - -pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { - if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { - return; - } - let cap = match ctx.config.snippet_cap { - Some(it) => it, - None => return, - }; - - snippet(ctx, cap, "pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); - snippet(ctx, cap, "ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); -} - -pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.is_new_item { - return; - } - let cap = match ctx.config.snippet_cap { - Some(it) => it, - None => return, - }; - - snippet( - ctx, - cap, - "tmod (Test module)", - "\ -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn ${1:test_name}() { - $0 - } -}", - ) - .lookup_by("tmod") - .add_to(acc); - - snippet( - ctx, - cap, - "tfn (Test function)", - "\ -#[test] -fn ${1:feature}() { - $0 -}", - ) - .lookup_by("tfn") - .add_to(acc); - - snippet(ctx, cap, "macro_rules", "macro_rules! $1 {\n\t($2) => {\n\t\t$0\n\t};\n}").add_to(acc); - snippet(ctx, cap, "pub(crate)", "pub(crate) $0").add_to(acc); -} - -#[cfg(test)] -mod tests { - use expect::{expect, Expect}; - - use crate::completion::{test_utils::completion_list, CompletionKind}; - - fn check(ra_fixture: &str, expect: Expect) { - let actual = completion_list(ra_fixture, CompletionKind::Snippet); - expect.assert_eq(&actual) - } - - #[test] - fn completes_snippets_in_expressions() { - check( - r#"fn foo(x: i32) { <|> }"#, - expect![[r#" - sn pd - sn ppd - "#]], - ); - } - - #[test] - fn should_not_complete_snippets_in_path() { - check(r#"fn foo(x: i32) { ::foo<|> }"#, expect![[""]]); - check(r#"fn foo(x: i32) { ::<|> }"#, expect![[""]]); - } - - #[test] - fn completes_snippets_in_items() { - check( - r#" -#[cfg(test)] -mod tests { - <|> -} -"#, - expect![[r#" - sn macro_rules - sn pub(crate) - sn tfn (Test function) - sn tmod (Test module) - "#]], - ) - } -} -- cgit v1.2.3