@@ -15,6 +15,19 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
1515 . ok_or_else ( || io_data_error ! ( "{:?} has no parent directory" , path) ) ?;
1616 let _ = create_dir_all ( dir) ;
1717
18+ // Determine comment prefix based on file extension
19+ let comment_prefix = match path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) {
20+ Some ( "rs" ) => "// " ,
21+ Some ( "java" ) => "// " ,
22+ Some ( "py" ) => "# " ,
23+ Some ( "sh" ) => "# " ,
24+ _ => "// " , // Default to // for unknown extensions
25+ } ;
26+
27+ // Create content with marker comment at the top
28+ let marker_line = format ! ( "{}{}\n " , comment_prefix, MARKER_COMMENT ) ;
29+ let full_contents = [ marker_line. as_bytes ( ) , contents] . concat ( ) ;
30+
1831 match File :: open ( path) {
1932 Ok ( file) => {
2033 let mut original = BufReader :: new ( file) ;
@@ -38,7 +51,7 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
3851 ) ;
3952 }
4053
41- let difference = Difference :: find ( & mut original, & mut Cursor :: new ( contents ) ) ?;
54+ let difference = Difference :: find ( & mut original, & mut Cursor :: new ( & full_contents ) ) ?;
4255 match difference {
4356 None => {
4457 context
@@ -69,7 +82,7 @@ pub fn write_generated(context: &emit::Context, path: &impl AsRef<Path>, content
6982 }
7083 } ;
7184
72- fs:: write ( path, contents )
85+ fs:: write ( path, & full_contents )
7386}
7487
7588fn read_line_no_eol ( reader : & mut impl BufRead , buffer : & mut String ) -> io:: Result < usize > {
0 commit comments