From 8be346bc90a276e9fe4123ce768d5a4b1c49b054 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 10 Apr 2025 17:01:02 +1200 Subject: [PATCH] Insert a newline between block comments and attributes Signed-off-by: Nick Cameron --- rust/kcl-lib/src/unparser.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rust/kcl-lib/src/unparser.rs b/rust/kcl-lib/src/unparser.rs index d0a189f90bd..3e9a10df7a0 100644 --- a/rust/kcl-lib/src/unparser.rs +++ b/rust/kcl-lib/src/unparser.rs @@ -195,7 +195,7 @@ impl Node { result.push_str(&indentation); result.push_str(comment); } - if !comment.ends_with("*/") && !result.ends_with("\n\n") && result != "\n" { + if !result.ends_with("\n\n") && result != "\n" { result.push('\n'); } } @@ -1048,6 +1048,20 @@ bar = 0 assert_eq!(output, input); } + #[test] + fn recast_annotations_with_block_comment() { + let input = r#"/* Start comment + +sdfsdfsdfs */ +@settings(defaultLengthUnit = in) + +foo = 42 +"#; + let program = crate::parsing::top_level_parse(input).unwrap(); + let output = program.recast(&Default::default(), 0); + assert_eq!(output, input); + } + #[test] fn test_recast_if_else_if_same() { let input = r#"b = if false {