diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-24 01:27:38 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-24 01:27:38 +0100 |
commit | 3a0a7081f4db293599bce5fab124cf258a946cb2 (patch) | |
tree | 2b3d64141d9797715914e2d26496eee7adb38a11 /crates/ra_ide/src/completion/complete_trait_impl.rs | |
parent | 601f89f2cb085ab7e638f034088f32b9428a0611 (diff) | |
parent | 5fd5de4061362aa1066cb9a47aa9cb79eab38e47 (diff) |
Merge #4116
4116: Make sure that adding a snippet requires corresponding capability r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion/complete_trait_impl.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index 2ec0e7ce9..c39943252 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -122,7 +122,7 @@ fn add_function_impl( | |||
122 | ctx: &CompletionContext, | 122 | ctx: &CompletionContext, |
123 | func: &hir::Function, | 123 | func: &hir::Function, |
124 | ) { | 124 | ) { |
125 | let display = FunctionSignature::from_hir(ctx.db, *func); | 125 | let signature = FunctionSignature::from_hir(ctx.db, *func); |
126 | 126 | ||
127 | let fn_name = func.name(ctx.db).to_string(); | 127 | let fn_name = func.name(ctx.db).to_string(); |
128 | 128 | ||
@@ -141,12 +141,20 @@ fn add_function_impl( | |||
141 | } else { | 141 | } else { |
142 | CompletionItemKind::Function | 142 | CompletionItemKind::Function |
143 | }; | 143 | }; |
144 | |||
145 | let snippet = format!("{} {{\n $0\n}}", display); | ||
146 | |||
147 | let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); | 144 | let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); |
148 | 145 | ||
149 | builder.snippet_edit(TextEdit::replace(range, snippet)).kind(completion_kind).add_to(acc); | 146 | match ctx.config.snippet_cap { |
147 | Some(cap) => { | ||
148 | let snippet = format!("{} {{\n $0\n}}", signature); | ||
149 | builder.snippet_edit(cap, TextEdit::replace(range, snippet)) | ||
150 | } | ||
151 | None => { | ||
152 | let header = format!("{} {{", signature); | ||
153 | builder.text_edit(TextEdit::replace(range, header)) | ||
154 | } | ||
155 | } | ||
156 | .kind(completion_kind) | ||
157 | .add_to(acc); | ||
150 | } | 158 | } |
151 | 159 | ||
152 | fn add_type_alias_impl( | 160 | fn add_type_alias_impl( |