From 317fc650d5c1267a8c192041efe6b591d900808f Mon Sep 17 00:00:00 2001 From: Timo Freiberg Date: Thu, 16 Apr 2020 23:53:25 +0200 Subject: Make add_function generate functions in other modules via qualified path --- crates/ra_syntax/src/ast/make.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast/make.rs') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 0f4a50be4..b0f4803f3 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -293,11 +293,16 @@ pub fn fn_def( ast_from_text(&format!("fn {}{}{} {}", fn_name, type_params, params, body)) } -pub fn add_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { +pub fn add_leading_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { let newlines = "\n".repeat(amount_of_newlines); ast_from_text(&format!("{}{}", newlines, t.syntax())) } +pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { + let newlines = "\n".repeat(amount_of_newlines); + ast_from_text(&format!("{}{}", t.syntax(), newlines)) +} + fn ast_from_text(text: &str) -> N { let parse = SourceFile::parse(text); let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); -- cgit v1.2.3 From f2f882bc44a85eb13276a8fbda7533d94e92e3af Mon Sep 17 00:00:00 2001 From: Timo Freiberg Date: Mon, 20 Apr 2020 18:36:12 +0200 Subject: Add `pub(crate)` to functions generated in other module --- crates/ra_syntax/src/ast/make.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'crates/ra_syntax/src/ast/make.rs') diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index b0f4803f3..ee0f5cc40 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -303,6 +303,10 @@ pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast: ast_from_text(&format!("{}{}", t.syntax(), newlines)) } +pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef { + ast_from_text(&format!("pub(crate) {}", fn_def)) +} + fn ast_from_text(text: &str) -> N { let parse = SourceFile::parse(text); let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); -- cgit v1.2.3