Support generic function in generate_function assist

This commit is contained in:
Ryo Yoshida 2023-01-31 19:49:18 +09:00
parent 32955c30cd
commit 3edde6fcc1
No known key found for this signature in database
GPG key ID: E25698A930586171
5 changed files with 888 additions and 45 deletions

View file

@ -823,6 +823,7 @@ pub fn fn_(
visibility: Option<ast::Visibility>,
fn_name: ast::Name,
type_params: Option<ast::GenericParamList>,
where_clause: Option<ast::WhereClause>,
params: ast::ParamList,
body: ast::BlockExpr,
ret_type: Option<ast::RetType>,
@ -832,6 +833,10 @@ pub fn fn_(
Some(type_params) => format!("{type_params}"),
None => "".into(),
};
let where_clause = match where_clause {
Some(it) => format!("{it} "),
None => "".into(),
};
let ret_type = match ret_type {
Some(ret_type) => format!("{ret_type} "),
None => "".into(),
@ -844,7 +849,7 @@ pub fn fn_(
let async_literal = if is_async { "async " } else { "" };
ast_from_text(&format!(
"{visibility}{async_literal}fn {fn_name}{type_params}{params} {ret_type}{body}",
"{visibility}{async_literal}fn {fn_name}{type_params}{params} {ret_type}{where_clause}{body}",
))
}