@@ -129,57 +129,74 @@ fn main() -> std::io::Result<()> {
129
129
node_types:: read_node_types_str ( "erb" , tree_sitter_embedded_template:: NODE_TYPES ) ?;
130
130
let lines: std:: io:: Result < Vec < String > > = std:: io:: BufReader :: new ( file_list) . lines ( ) . collect ( ) ;
131
131
let lines = lines?;
132
- lines. par_iter ( ) . try_for_each ( |line| {
133
- let path = PathBuf :: from ( line) . canonicalize ( ) ?;
134
- let trap_file = path_for ( & trap_dir, & path, trap_compression. extension ( ) ) ;
135
- let src_archive_file = path_for ( & src_archive_dir, & path, "" ) ;
136
- let mut source = std:: fs:: read ( & path) ?;
137
- let code_ranges;
138
- let mut trap_writer = extractor:: new_trap_writer ( ) ;
139
- if path. extension ( ) . map_or ( false , |x| x == "erb" ) {
140
- tracing:: info!( "scanning: {}" , path. display( ) ) ;
132
+ lines
133
+ . par_iter ( )
134
+ . try_for_each ( |line| {
135
+ let path = PathBuf :: from ( line) . canonicalize ( ) ?;
136
+ let src_archive_file = path_for ( & src_archive_dir, & path, "" ) ;
137
+ let mut source = std:: fs:: read ( & path) ?;
138
+ let code_ranges;
139
+ let mut trap_writer = extractor:: new_trap_writer ( ) ;
140
+ if path. extension ( ) . map_or ( false , |x| x == "erb" ) {
141
+ tracing:: info!( "scanning: {}" , path. display( ) ) ;
142
+ extractor:: extract (
143
+ erb,
144
+ "erb" ,
145
+ & erb_schema,
146
+ & mut trap_writer,
147
+ & path,
148
+ & source,
149
+ & [ ] ,
150
+ ) ?;
151
+
152
+ let ( ranges, line_breaks) = scan_erb ( erb, & source) ;
153
+ for i in line_breaks {
154
+ if i < source. len ( ) {
155
+ source[ i] = b'\n' ;
156
+ }
157
+ }
158
+ code_ranges = ranges;
159
+ } else {
160
+ code_ranges = vec ! [ ] ;
161
+ }
141
162
extractor:: extract (
142
- erb ,
143
- "erb " ,
144
- & erb_schema ,
163
+ language ,
164
+ "ruby " ,
165
+ & schema ,
145
166
& mut trap_writer,
146
167
& path,
147
168
& source,
148
- & [ ] ,
169
+ & code_ranges ,
149
170
) ?;
171
+ std:: fs:: create_dir_all ( & src_archive_file. parent ( ) . unwrap ( ) ) ?;
172
+ std:: fs:: copy ( & path, & src_archive_file) ?;
173
+ write_trap ( & trap_dir, path, trap_writer, & trap_compression)
174
+ } )
175
+ . expect ( "failed to extract files" ) ;
150
176
151
- let ( ranges, line_breaks) = scan_erb ( erb, & source) ;
152
- for i in line_breaks {
153
- if i < source. len ( ) {
154
- source[ i] = b'\n' ;
155
- }
156
- }
157
- code_ranges = ranges;
158
- } else {
159
- code_ranges = vec ! [ ] ;
160
- }
161
- extractor:: extract (
162
- language,
163
- "ruby" ,
164
- & schema,
165
- & mut trap_writer,
166
- & path,
167
- & source,
168
- & code_ranges,
169
- ) ?;
170
- std:: fs:: create_dir_all ( & src_archive_file. parent ( ) . unwrap ( ) ) ?;
171
- std:: fs:: copy ( & path, & src_archive_file) ?;
172
- std:: fs:: create_dir_all ( & trap_file. parent ( ) . unwrap ( ) ) ?;
173
- let trap_file = std:: fs:: File :: create ( & trap_file) ?;
174
- let mut trap_file = BufWriter :: new ( trap_file) ;
175
- match trap_compression {
176
- TrapCompression :: None => trap_writer. output ( & mut trap_file) ,
177
- TrapCompression :: Gzip => {
178
- let mut compressed_writer = GzEncoder :: new ( trap_file, flate2:: Compression :: fast ( ) ) ;
179
- trap_writer. output ( & mut compressed_writer)
180
- }
177
+ let path = PathBuf :: from ( "extras" ) ;
178
+ let mut trap_writer = extractor:: new_trap_writer ( ) ;
179
+ trap_writer. populate_empty_location ( ) ;
180
+ write_trap ( & trap_dir, path, trap_writer, & trap_compression)
181
+ }
182
+
183
+ fn write_trap (
184
+ trap_dir : & PathBuf ,
185
+ path : PathBuf ,
186
+ trap_writer : extractor:: TrapWriter ,
187
+ trap_compression : & TrapCompression ,
188
+ ) -> std:: io:: Result < ( ) > {
189
+ let trap_file = path_for ( & trap_dir, & path, trap_compression. extension ( ) ) ;
190
+ std:: fs:: create_dir_all ( & trap_file. parent ( ) . unwrap ( ) ) ?;
191
+ let trap_file = std:: fs:: File :: create ( & trap_file) ?;
192
+ let mut trap_file = BufWriter :: new ( trap_file) ;
193
+ match trap_compression {
194
+ TrapCompression :: None => trap_writer. output ( & mut trap_file) ,
195
+ TrapCompression :: Gzip => {
196
+ let mut compressed_writer = GzEncoder :: new ( trap_file, flate2:: Compression :: fast ( ) ) ;
197
+ trap_writer. output ( & mut compressed_writer)
181
198
}
182
- } )
199
+ }
183
200
}
184
201
185
202
fn scan_erb ( erb : Language , source : & std:: vec:: Vec < u8 > ) -> ( Vec < Range > , Vec < usize > ) {
0 commit comments