diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 25 |
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 d0e960fb4..b275780ec 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -277,7 +277,12 @@ pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList | |||
277 | ast_from_text(&format!("fn f({}) {{ }}", args)) | 277 | ast_from_text(&format!("fn f({}) {{ }}", args)) |
278 | } | 278 | } |
279 | 279 | ||
280 | pub fn visibility_pub_crate() -> ast::Visibility { | ||
281 | ast_from_text("pub(crate) struct S") | ||
282 | } | ||
283 | |||
280 | pub fn fn_def( | 284 | pub fn fn_def( |
285 | visibility: Option<ast::Visibility>, | ||
281 | fn_name: ast::Name, | 286 | fn_name: ast::Name, |
282 | type_params: Option<ast::TypeParamList>, | 287 | type_params: Option<ast::TypeParamList>, |
283 | params: ast::ParamList, | 288 | params: ast::ParamList, |
@@ -285,21 +290,11 @@ pub fn fn_def( | |||
285 | ) -> ast::FnDef { | 290 | ) -> ast::FnDef { |
286 | let type_params = | 291 | let type_params = |
287 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; | 292 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; |
288 | ast_from_text(&format!("fn {}{}{} {}", fn_name, type_params, params, body)) | 293 | let visibility = match visibility { |
289 | } | 294 | None => String::new(), |
290 | 295 | Some(it) => format!("{} ", it), | |
291 | pub fn add_leading_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { | 296 | }; |
292 | let newlines = "\n".repeat(amount_of_newlines); | 297 | ast_from_text(&format!("{}fn {}{}{} {}", visibility, fn_name, type_params, params, body)) |
293 | ast_from_text(&format!("{}{}", newlines, t.syntax())) | ||
294 | } | ||
295 | |||
296 | pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { | ||
297 | let newlines = "\n".repeat(amount_of_newlines); | ||
298 | ast_from_text(&format!("{}{}", t.syntax(), newlines)) | ||
299 | } | ||
300 | |||
301 | pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef { | ||
302 | ast_from_text(&format!("pub(crate) {}", fn_def)) | ||
303 | } | 298 | } |
304 | 299 | ||
305 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 300 | fn ast_from_text<N: AstNode>(text: &str) -> N { |