fmt: keep same line comment in array init (#7980)
							parent
							
								
									2103d9a6c4
								
							
						
					
					
						commit
						c1b1ec9005
					
				| 
						 | 
				
			
			@ -1944,7 +1944,10 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
 | 
			
		|||
				f.array_init_break << (last_line_nr < line_nr)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		mut penalty := if f.array_init_break[f.array_init_depth - 1] { 0 } else { 3 }
 | 
			
		||||
		is_same_line_comment := i > 0 &&
 | 
			
		||||
			(expr is ast.Comment && line_nr == it.exprs[i - 1].position().line_nr)
 | 
			
		||||
		line_break := f.array_init_break[f.array_init_depth - 1]
 | 
			
		||||
		mut penalty := if line_break && !is_same_line_comment { 0 } else { 3 }
 | 
			
		||||
		if penalty > 0 {
 | 
			
		||||
			if i == 0 || it.exprs[i - 1] is ast.ArrayInit || it.exprs[i - 1] is ast.StructInit ||
 | 
			
		||||
				it.exprs[i - 1] is ast.MapInit || it.exprs[i - 1] is ast.CallExpr {
 | 
			
		||||
| 
						 | 
				
			
			@ -1976,6 +1979,8 @@ pub fn (mut f Fmt) array_init(it ast.ArrayInit) {
 | 
			
		|||
					f.write(',')
 | 
			
		||||
				}
 | 
			
		||||
				f.writeln('')
 | 
			
		||||
			} else if is_same_line_comment {
 | 
			
		||||
				f.writeln('')
 | 
			
		||||
			}
 | 
			
		||||
		} else if expr !is ast.Comment {
 | 
			
		||||
			f.write(',')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ fn main() {
 | 
			
		|||
		/* test 1 */
 | 
			
		||||
		2,
 | 
			
		||||
		/* test 2 */
 | 
			
		||||
		3, /* 3 */
 | 
			
		||||
		4, /* 4-1 */ /* 4-2 */
 | 
			
		||||
	]
 | 
			
		||||
	arr2 := [
 | 
			
		||||
		'foo',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue