From 3b75bc154f75cb97ff2debee9f6594d6fc4f4053 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 17 Apr 2020 11:55:06 +0200 Subject: Better snippet when completing trait method --- crates/ra_ide/src/completion/complete_trait_impl.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index fab02945c..2ec0e7ce9 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -142,11 +142,11 @@ fn add_function_impl( CompletionItemKind::Function }; - let snippet = format!("{} {{}}", display); + let snippet = format!("{} {{\n $0\n}}", display); let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); - builder.text_edit(TextEdit::replace(range, snippet)).kind(completion_kind).add_to(acc); + builder.snippet_edit(TextEdit::replace(range, snippet)).kind(completion_kind).add_to(acc); } fn add_type_alias_impl( @@ -217,9 +217,10 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { #[cfg(test)] mod tests { - use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot; + use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; + fn complete(code: &str) -> Vec { do_completion(code, CompletionKind::Magic) } @@ -255,7 +256,7 @@ mod tests { label: "fn test()", source_range: [209; 210), delete: [209; 210), - insert: "fn test() {}", + insert: "fn test() {\n $0\n}", kind: Function, lookup: "test", }, @@ -313,7 +314,7 @@ mod tests { label: "fn test()", source_range: [139; 140), delete: [139; 140), - insert: "fn test() {}", + insert: "fn test() {\n $0\n}", kind: Function, lookup: "test", }, @@ -342,7 +343,7 @@ mod tests { label: "fn foo()", source_range: [141; 142), delete: [138; 142), - insert: "fn foo() {}", + insert: "fn foo() {\n $0\n}", kind: Function, lookup: "foo", }, @@ -374,7 +375,7 @@ mod tests { label: "fn foo_bar()", source_range: [200; 201), delete: [197; 201), - insert: "fn foo_bar() {}", + insert: "fn foo_bar() {\n $0\n}", kind: Function, lookup: "foo_bar", }, @@ -425,7 +426,7 @@ mod tests { label: "fn foo()", source_range: [144; 145), delete: [141; 145), - insert: "fn foo() {}", + insert: "fn foo() {\n $0\n}", kind: Function, lookup: "foo", }, @@ -454,7 +455,7 @@ mod tests { label: "fn foo()", source_range: [166; 167), delete: [163; 167), - insert: "fn foo()\nwhere T: Into {}", + insert: "fn foo()\nwhere T: Into {\n $0\n}", kind: Function, lookup: "foo", }, -- cgit v1.2.3