aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-06 16:51:10 +0000
committerAleksey Kladov <[email protected]>2020-03-06 16:51:10 +0000
commit4e7f6c235489eb40c85bb73e75beead3ea7f08c7 (patch)
tree87623cdec8b374953f69cb3e46a73aa2c6bd7006
parent21f40f2b8f2d2ce19c2bc69201e99503a8d15e04 (diff)
Feature flag for arg snippets
-rw-r--r--crates/ra_ide/src/completion/presentation.rs17
-rw-r--r--crates/ra_ide_db/src/feature_flags.rs1
-rw-r--r--editors/code/package.json4
3 files changed, 18 insertions, 4 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index e623c47ec..841d36c8f 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -221,16 +221,25 @@ impl Completions {
221 let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { 221 let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 {
222 (format!("{}()$0", name), format!("{}()", name)) 222 (format!("{}()$0", name), format!("{}()", name))
223 } else { 223 } else {
224 let to_skip = if has_self_param { 1 } else { 0 }; 224 let snippet = if ctx
225 let function_params_snippet = 225 .db
226 join( 226 .feature_flags
227 .get("completion.insertion.add-argument-sippets")
228 {
229 let to_skip = if has_self_param { 1 } else { 0 };
230 let function_params_snippet = join(
227 function_signature.parameter_names.iter().skip(to_skip).enumerate().map( 231 function_signature.parameter_names.iter().skip(to_skip).enumerate().map(
228 |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), 232 |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name),
229 ), 233 ),
230 ) 234 )
231 .separator(", ") 235 .separator(", ")
232 .to_string(); 236 .to_string();
233 (format!("{}({})$0", name, function_params_snippet), format!("{}(…)", name)) 237 format!("{}({})$0", name, function_params_snippet)
238 } else {
239 format!("{}($0)", name)
240 };
241
242 (snippet, format!("{}(…)", name))
234 }; 243 };
235 builder = builder.lookup_by(name).label(label).insert_snippet(snippet); 244 builder = builder.lookup_by(name).label(label).insert_snippet(snippet);
236 } 245 }
diff --git a/crates/ra_ide_db/src/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs
index 76655f572..d9c9d6cd2 100644
--- a/crates/ra_ide_db/src/feature_flags.rs
+++ b/crates/ra_ide_db/src/feature_flags.rs
@@ -54,6 +54,7 @@ impl Default for FeatureFlags {
54 FeatureFlags::new(&[ 54 FeatureFlags::new(&[
55 ("lsp.diagnostics", true), 55 ("lsp.diagnostics", true),
56 ("completion.insertion.add-call-parenthesis", true), 56 ("completion.insertion.add-call-parenthesis", true),
57 ("completion.insertion.add-argument-sippets", true),
57 ("completion.enable-postfix", true), 58 ("completion.enable-postfix", true),
58 ("notifications.workspace-loaded", true), 59 ("notifications.workspace-loaded", true),
59 ("notifications.cargo-toml-not-found", true), 60 ("notifications.cargo-toml-not-found", true),
diff --git a/editors/code/package.json b/editors/code/package.json
index 830358605..2f442aae8 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -197,6 +197,10 @@
197 "type": "boolean", 197 "type": "boolean",
198 "description": "Whether to add parenthesis when completing functions" 198 "description": "Whether to add parenthesis when completing functions"
199 }, 199 },
200 "completion.insertion.add-argument-sippets": {
201 "type": "boolean",
202 "description": "Whether to add argument snippets when completing functions"
203 },
200 "completion.enable-postfix": { 204 "completion.enable-postfix": {
201 "type": "boolean", 205 "type": "boolean",
202 "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." 206 "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc."