From 4e7f6c235489eb40c85bb73e75beead3ea7f08c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 6 Mar 2020 17:51:10 +0100 Subject: Feature flag for arg snippets --- crates/ra_ide/src/completion/presentation.rs | 17 +++++++++++++---- crates/ra_ide_db/src/feature_flags.rs | 1 + editors/code/package.json | 4 ++++ 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 { let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { (format!("{}()$0", name), format!("{}()", name)) } else { - let to_skip = if has_self_param { 1 } else { 0 }; - let function_params_snippet = - join( + let snippet = if ctx + .db + .feature_flags + .get("completion.insertion.add-argument-sippets") + { + let to_skip = if has_self_param { 1 } else { 0 }; + let function_params_snippet = join( function_signature.parameter_names.iter().skip(to_skip).enumerate().map( |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), ), ) .separator(", ") .to_string(); - (format!("{}({})$0", name, function_params_snippet), format!("{}(…)", name)) + format!("{}({})$0", name, function_params_snippet) + } else { + format!("{}($0)", name) + }; + + (snippet, format!("{}(…)", name)) }; builder = builder.lookup_by(name).label(label).insert_snippet(snippet); } 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 { FeatureFlags::new(&[ ("lsp.diagnostics", true), ("completion.insertion.add-call-parenthesis", true), + ("completion.insertion.add-argument-sippets", true), ("completion.enable-postfix", true), ("notifications.workspace-loaded", true), ("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 @@ "type": "boolean", "description": "Whether to add parenthesis when completing functions" }, + "completion.insertion.add-argument-sippets": { + "type": "boolean", + "description": "Whether to add argument snippets when completing functions" + }, "completion.enable-postfix": { "type": "boolean", "description": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc." -- cgit v1.2.3