From 3bfa3e8123dd2d652019ad270622025d10b87cc8 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Sun, 4 Oct 2020 21:21:30 +0200 Subject: when generating new function, focus on return type instead of body Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/syntax/src/ast/make.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/syntax') diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 3a184094c..74dbdfaf7 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -320,6 +320,10 @@ pub fn param(name: String, ty: String) -> ast::Param { ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) } +pub fn ret_type(ty: ast::Type) -> ast::RetType { + ast_from_text(&format!("fn f() -> {} {{ }}", ty)) +} + pub fn param_list(pats: impl IntoIterator) -> ast::ParamList { let args = pats.into_iter().join(", "); ast_from_text(&format!("fn f({}) {{ }}", args)) @@ -350,14 +354,20 @@ pub fn fn_( type_params: Option, params: ast::ParamList, body: ast::BlockExpr, + ret_type: Option, ) -> ast::Fn { let type_params = if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; + let ret_type = if let Some(ret_type) = ret_type { format!("{} ", ret_type) } else { "".into() }; let visibility = match visibility { None => String::new(), Some(it) => format!("{} ", it), }; - ast_from_text(&format!("{}fn {}{}{} {}", visibility, fn_name, type_params, params, body)) + + ast_from_text(&format!( + "{}fn {}{}{} {}{}", + visibility, fn_name, type_params, params, ret_type, body + )) } fn ast_from_text(text: &str) -> N { -- cgit v1.2.3