-
Notifications
You must be signed in to change notification settings - Fork 1.8k
$0 in extract function assist #7793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks like we don't honor the snippet capabilities in that assist https://github.com/rust-analyzer/rust-analyzer/blob/d5b8a401f38f88ecb0d894c88dcbab3d338a0ef2/crates/ide_assists/src/handlers/extract_function.rs#L1071-L1089 |
The fix is to check for the capability like done in |
@Veykril you mean like this? That simple? Simply return fn format_function(
ctx: &AssistContext,
module: hir::Module,
fun: &Function,
old_indent: IndentLevel,
new_indent: IndentLevel,
) -> String {
let mut fn_def = String::new();
match ctx.config.snippet_cap {
None => (),
Some(_) => {
let params = make_param_list(ctx, module, fun);
let ret_ty = make_ret_ty(ctx, module, fun);
let body = make_body(ctx, old_indent, new_indent, fun);
format_to!(fn_def, "\n\n{}fn $0{}{}", new_indent, fun.name, params);
if let Some(ret_ty) = ret_ty {
format_to!(fn_def, " {}", ret_ty);
}
format_to!(fn_def, " {}", body);
}
};
fn_def
} |
No not quite, we still want to emit the code but dont want to emit the |
I've go the changes in my fork, would that be sufficient to close the issue ? edit Looking in the match ctx.config.snippet_cap {
Some(_) => {
builder.insert_snippet(ctx.config.snippet_cap.unwrap(), insert_offset, fn_def)
}
None => builder.insert(insert_offset, fn_def),
} also, or is this not a "snippet insertion" per se ? |
Ye I think that also has to be changed |
7880: Honor snippet capability when using the extract function assist r=lnicola a=Arthamys This fixes issue #7793 Co-authored-by: san <[email protected]>
Fixed by #7880. |
Uh oh!
There was an error while loading. Please reload this page.
Hello, I am using nvim + LanguageClient-neovim and I have no plugin for snippet support. When I use the "extract function assist" code action, the generated function always has the name $0fun_name. The same happens with nvim-lsp. If I understand #2518 and #4117 correctly, snippet-completion should be disabled automatically if the client does not support snippets.
The text was updated successfully, but these errors were encountered: