@@ -199,139 +199,143 @@ fn format_body(slice: &snippet::Slice, has_footer: bool) -> Vec<DisplayLine> {
199
199
let mut annotations = slice. annotations . clone ( ) ;
200
200
for idx in 0 ..body. len ( ) {
201
201
let ( line_start, line_end) = line_index_ranges[ idx] ;
202
- annotations. drain_filter ( |annotation| {
203
- let body_idx = idx + annotation_line_count;
204
- let annotation_type = match annotation. annotation_type {
205
- snippet:: AnnotationType :: Error => DisplayAnnotationType :: None ,
206
- snippet:: AnnotationType :: Warning => DisplayAnnotationType :: None ,
207
- _ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
208
- } ;
209
- match annotation. range {
210
- ( start, _) if start > line_end => false ,
211
- ( start, end) if start >= line_start && end <= line_end + 1 => {
212
- let range = ( start - line_start, end - line_start) ;
213
- body. insert (
214
- body_idx + 1 ,
215
- DisplayLine :: Source {
216
- lineno : None ,
217
- inline_marks : vec ! [ ] ,
218
- line : DisplaySourceLine :: Annotation {
219
- annotation : Annotation {
220
- annotation_type,
221
- id : None ,
222
- label : format_label ( Some ( & annotation. label ) , None ) ,
202
+ // It would be nice to use filter_drain here once it's stable.
203
+ annotations = annotations
204
+ . into_iter ( )
205
+ . filter ( |annotation| {
206
+ let body_idx = idx + annotation_line_count;
207
+ let annotation_type = match annotation. annotation_type {
208
+ snippet:: AnnotationType :: Error => DisplayAnnotationType :: None ,
209
+ snippet:: AnnotationType :: Warning => DisplayAnnotationType :: None ,
210
+ _ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
211
+ } ;
212
+ match annotation. range {
213
+ ( start, _) if start > line_end => true ,
214
+ ( start, end) if start >= line_start && end <= line_end + 1 => {
215
+ let range = ( start - line_start, end - line_start) ;
216
+ body. insert (
217
+ body_idx + 1 ,
218
+ DisplayLine :: Source {
219
+ lineno : None ,
220
+ inline_marks : vec ! [ ] ,
221
+ line : DisplaySourceLine :: Annotation {
222
+ annotation : Annotation {
223
+ annotation_type,
224
+ id : None ,
225
+ label : format_label ( Some ( & annotation. label ) , None ) ,
226
+ } ,
227
+ range,
228
+ annotation_type : DisplayAnnotationType :: from (
229
+ annotation. annotation_type ,
230
+ ) ,
231
+ annotation_part : DisplayAnnotationPart :: Standalone ,
223
232
} ,
224
- range,
233
+ } ,
234
+ ) ;
235
+ annotation_line_count += 1 ;
236
+ false
237
+ }
238
+ ( start, end) if start >= line_start && start <= line_end && end > line_end => {
239
+ if start - line_start == 0 {
240
+ if let DisplayLine :: Source {
241
+ ref mut inline_marks,
242
+ ..
243
+ } = body[ body_idx]
244
+ {
245
+ inline_marks. push ( DisplayMark {
246
+ mark_type : DisplayMarkType :: AnnotationStart ,
247
+ annotation_type : DisplayAnnotationType :: from (
248
+ annotation. annotation_type ,
249
+ ) ,
250
+ } ) ;
251
+ }
252
+ } else {
253
+ let range = ( start - line_start, start - line_start + 1 ) ;
254
+ body. insert (
255
+ body_idx + 1 ,
256
+ DisplayLine :: Source {
257
+ lineno : None ,
258
+ inline_marks : vec ! [ ] ,
259
+ line : DisplaySourceLine :: Annotation {
260
+ annotation : Annotation {
261
+ annotation_type : DisplayAnnotationType :: None ,
262
+ id : None ,
263
+ label : vec ! [ ] ,
264
+ } ,
265
+ range,
266
+ annotation_type : DisplayAnnotationType :: from (
267
+ annotation. annotation_type ,
268
+ ) ,
269
+ annotation_part : DisplayAnnotationPart :: MultilineStart ,
270
+ } ,
271
+ } ,
272
+ ) ;
273
+ annotation_line_count += 1 ;
274
+ }
275
+ true
276
+ }
277
+ ( start, end) if start < line_start && end > line_end => {
278
+ if let DisplayLine :: Source {
279
+ ref mut inline_marks,
280
+ ..
281
+ } = body[ body_idx]
282
+ {
283
+ inline_marks. push ( DisplayMark {
284
+ mark_type : DisplayMarkType :: AnnotationThrough ,
225
285
annotation_type : DisplayAnnotationType :: from (
226
286
annotation. annotation_type ,
227
287
) ,
228
- annotation_part : DisplayAnnotationPart :: Standalone ,
229
- } ,
230
- } ,
231
- ) ;
232
- annotation_line_count += 1 ;
233
- true
234
- }
235
- ( start, end) if start >= line_start && start <= line_end && end > line_end => {
236
- if start - line_start == 0 {
288
+ } ) ;
289
+ }
290
+ true
291
+ }
292
+ ( start, end) if start < line_start && end >= line_start && end <= line_end => {
237
293
if let DisplayLine :: Source {
238
294
ref mut inline_marks,
239
295
..
240
296
} = body[ body_idx]
241
297
{
242
298
inline_marks. push ( DisplayMark {
243
- mark_type : DisplayMarkType :: AnnotationStart ,
299
+ mark_type : DisplayMarkType :: AnnotationThrough ,
244
300
annotation_type : DisplayAnnotationType :: from (
245
301
annotation. annotation_type ,
246
302
) ,
247
303
} ) ;
248
304
}
249
- } else {
250
- let range = ( start - line_start, start - line_start + 1 ) ;
305
+ let range = ( end - line_start, end - line_start + 1 ) ;
251
306
body. insert (
252
307
body_idx + 1 ,
253
308
DisplayLine :: Source {
254
309
lineno : None ,
255
- inline_marks : vec ! [ ] ,
310
+ inline_marks : vec ! [
311
+ DisplayMark {
312
+ mark_type: DisplayMarkType :: AnnotationThrough ,
313
+ annotation_type: DisplayAnnotationType :: from(
314
+ annotation. annotation_type,
315
+ ) ,
316
+ } ,
317
+ ] ,
256
318
line : DisplaySourceLine :: Annotation {
257
319
annotation : Annotation {
258
- annotation_type : DisplayAnnotationType :: None ,
320
+ annotation_type,
259
321
id : None ,
260
- label : vec ! [ ] ,
322
+ label : format_label ( Some ( & annotation . label ) , None ) ,
261
323
} ,
262
324
range,
263
325
annotation_type : DisplayAnnotationType :: from (
264
326
annotation. annotation_type ,
265
327
) ,
266
- annotation_part : DisplayAnnotationPart :: MultilineStart ,
328
+ annotation_part : DisplayAnnotationPart :: MultilineEnd ,
267
329
} ,
268
330
} ,
269
331
) ;
270
332
annotation_line_count += 1 ;
333
+ false
271
334
}
272
- false
273
- }
274
- ( start, end) if start < line_start && end > line_end => {
275
- if let DisplayLine :: Source {
276
- ref mut inline_marks,
277
- ..
278
- } = body[ body_idx]
279
- {
280
- inline_marks. push ( DisplayMark {
281
- mark_type : DisplayMarkType :: AnnotationThrough ,
282
- annotation_type : DisplayAnnotationType :: from (
283
- annotation. annotation_type ,
284
- ) ,
285
- } ) ;
286
- }
287
- false
335
+ _ => true ,
288
336
}
289
- ( start, end) if start < line_start && end >= line_start && end <= line_end => {
290
- if let DisplayLine :: Source {
291
- ref mut inline_marks,
292
- ..
293
- } = body[ body_idx]
294
- {
295
- inline_marks. push ( DisplayMark {
296
- mark_type : DisplayMarkType :: AnnotationThrough ,
297
- annotation_type : DisplayAnnotationType :: from (
298
- annotation. annotation_type ,
299
- ) ,
300
- } ) ;
301
- }
302
- let range = ( end - line_start, end - line_start + 1 ) ;
303
- body. insert (
304
- body_idx + 1 ,
305
- DisplayLine :: Source {
306
- lineno : None ,
307
- inline_marks : vec ! [
308
- DisplayMark {
309
- mark_type: DisplayMarkType :: AnnotationThrough ,
310
- annotation_type: DisplayAnnotationType :: from(
311
- annotation. annotation_type,
312
- ) ,
313
- } ,
314
- ] ,
315
- line : DisplaySourceLine :: Annotation {
316
- annotation : Annotation {
317
- annotation_type,
318
- id : None ,
319
- label : format_label ( Some ( & annotation. label ) , None ) ,
320
- } ,
321
- range,
322
- annotation_type : DisplayAnnotationType :: from (
323
- annotation. annotation_type ,
324
- ) ,
325
- annotation_part : DisplayAnnotationPart :: MultilineEnd ,
326
- } ,
327
- } ,
328
- ) ;
329
- annotation_line_count += 1 ;
330
- true
331
- }
332
- _ => false ,
333
- }
334
- } ) ;
337
+ } )
338
+ . collect ( ) ;
335
339
}
336
340
337
341
if slice. fold {
0 commit comments