Feature flag for arg snippets

This commit is contained in:
Aleksey Kladov 2020-03-06 17:51:10 +01:00
parent 21f40f2b8f
commit 4e7f6c2354
3 changed files with 18 additions and 4 deletions

View File

@ -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);
}

View File

@ -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),

View File

@ -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."