aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/make.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r--crates/ra_syntax/src/ast/make.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 2db017038..da0eb0926 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -280,7 +280,12 @@ pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList
280 ast_from_text(&format!("fn f({}) {{ }}", args)) 280 ast_from_text(&format!("fn f({}) {{ }}", args))
281} 281}
282 282
283pub fn visibility_pub_crate() -> ast::Visibility {
284 ast_from_text("pub(crate) struct S")
285}
286
283pub fn fn_def( 287pub fn fn_def(
288 visibility: Option<ast::Visibility>,
284 fn_name: ast::Name, 289 fn_name: ast::Name,
285 type_params: Option<ast::TypeParamList>, 290 type_params: Option<ast::TypeParamList>,
286 params: ast::ParamList, 291 params: ast::ParamList,
@@ -288,21 +293,11 @@ pub fn fn_def(
288) -> ast::FnDef { 293) -> ast::FnDef {
289 let type_params = 294 let type_params =
290 if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; 295 if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() };
291 ast_from_text(&format!("fn {}{}{} {}", fn_name, type_params, params, body)) 296 let visibility = match visibility {
292} 297 None => String::new(),
293 298 Some(it) => format!("{} ", it),
294pub fn add_leading_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { 299 };
295 let newlines = "\n".repeat(amount_of_newlines); 300 ast_from_text(&format!("{}fn {}{}{} {}", visibility, fn_name, type_params, params, body))
296 ast_from_text(&format!("{}{}", newlines, t.syntax()))
297}
298
299pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile {
300 let newlines = "\n".repeat(amount_of_newlines);
301 ast_from_text(&format!("{}{}", t.syntax(), newlines))
302}
303
304pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef {
305 ast_from_text(&format!("pub(crate) {}", fn_def))
306} 301}
307 302
308fn ast_from_text<N: AstNode>(text: &str) -> N { 303fn ast_from_text<N: AstNode>(text: &str) -> N {