@@ -11,9 +11,9 @@ impl<'a> CursorLines<'a> {
11
11
}
12
12
13
13
enum EndLine {
14
- EOF = 0 ,
15
- CRLF = 1 ,
16
- LF = 2 ,
14
+ Eof = 0 ,
15
+ Crlf = 1 ,
16
+ Lf = 2 ,
17
17
}
18
18
19
19
impl < ' a > Iterator for CursorLines < ' a > {
@@ -28,18 +28,18 @@ impl<'a> Iterator for CursorLines<'a> {
28
28
. map ( |x| {
29
29
let ret = if 0 < x {
30
30
if self . 0 . as_bytes ( ) [ x - 1 ] == b'\r' {
31
- ( & self . 0 [ ..x - 1 ] , EndLine :: LF )
31
+ ( & self . 0 [ ..x - 1 ] , EndLine :: Lf )
32
32
} else {
33
- ( & self . 0 [ ..x] , EndLine :: CRLF )
33
+ ( & self . 0 [ ..x] , EndLine :: Crlf )
34
34
}
35
35
} else {
36
- ( "" , EndLine :: CRLF )
36
+ ( "" , EndLine :: Crlf )
37
37
} ;
38
38
self . 0 = & self . 0 [ x + 1 ..] ;
39
39
ret
40
40
} )
41
41
. or_else ( || {
42
- let ret = Some ( ( self . 0 , EndLine :: EOF ) ) ;
42
+ let ret = Some ( ( self . 0 , EndLine :: Eof ) ) ;
43
43
self . 0 = "" ;
44
44
ret
45
45
} )
@@ -330,171 +330,168 @@ fn format_body(
330
330
. map ( |m| m. left ( line_end_index - line_start_index) )
331
331
. unwrap_or_default ( ) ;
332
332
// It would be nice to use filter_drain here once it's stable.
333
- annotations = annotations
334
- . into_iter ( )
335
- . filter ( |annotation| {
336
- let body_idx = idx + annotation_line_count;
337
- let annotation_type = match annotation. annotation_type {
338
- snippet:: AnnotationType :: Error => DisplayAnnotationType :: None ,
339
- snippet:: AnnotationType :: Warning => DisplayAnnotationType :: None ,
340
- _ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
341
- } ;
342
- match annotation. range {
343
- ( start, _) if start > line_end_index => true ,
344
- ( start, end)
345
- if start >= line_start_index && end <= line_end_index
346
- || start == line_end_index && end - start <= 1 =>
347
- {
348
- let annotation_start_col = char_widths
349
- . iter ( )
350
- . take ( start - line_start_index)
351
- . sum :: < usize > ( )
352
- - margin_left;
353
- let annotation_end_col = char_widths
354
- . iter ( )
355
- . take ( end - line_start_index)
356
- . sum :: < usize > ( )
357
- - margin_left;
358
- let range = ( annotation_start_col, annotation_end_col) ;
359
- body. insert (
360
- body_idx + 1 ,
361
- DisplayLine :: Source {
362
- lineno : None ,
363
- inline_marks : vec ! [ ] ,
364
- line : DisplaySourceLine :: Annotation {
365
- annotation : Annotation {
366
- annotation_type,
367
- id : None ,
368
- label : format_label ( Some ( annotation. label ) , None ) ,
369
- } ,
370
- range,
371
- annotation_type : DisplayAnnotationType :: from (
372
- annotation. annotation_type ,
373
- ) ,
374
- annotation_part : DisplayAnnotationPart :: Standalone ,
375
- } ,
376
- } ,
377
- ) ;
378
- annotation_line_count += 1 ;
379
- false
380
- }
381
- ( start, end)
382
- if start >= line_start_index
383
- && start <= line_end_index
384
- && end > line_end_index =>
385
- {
386
- if start - line_start_index == 0 {
387
- if let DisplayLine :: Source {
388
- ref mut inline_marks,
389
- ..
390
- } = body[ body_idx]
391
- {
392
- inline_marks. push ( DisplayMark {
393
- mark_type : DisplayMarkType :: AnnotationStart ,
394
- annotation_type : DisplayAnnotationType :: from (
395
- annotation. annotation_type ,
396
- ) ,
397
- } ) ;
398
- }
399
- } else {
400
- let annotation_start_col = char_widths
401
- . iter ( )
402
- . take ( start - line_start_index)
403
- . sum :: < usize > ( ) ;
404
- let range = ( annotation_start_col, annotation_start_col + 1 ) ;
405
- body. insert (
406
- body_idx + 1 ,
407
- DisplayLine :: Source {
408
- lineno : None ,
409
- inline_marks : vec ! [ ] ,
410
- line : DisplaySourceLine :: Annotation {
411
- annotation : Annotation {
412
- annotation_type : DisplayAnnotationType :: None ,
413
- id : None ,
414
- label : vec ! [ ] ,
415
- } ,
416
- range,
417
- annotation_type : DisplayAnnotationType :: from (
418
- annotation. annotation_type ,
419
- ) ,
420
- annotation_part : DisplayAnnotationPart :: MultilineStart ,
421
- } ,
333
+ annotations. retain ( |annotation| {
334
+ let body_idx = idx + annotation_line_count;
335
+ let annotation_type = match annotation. annotation_type {
336
+ snippet:: AnnotationType :: Error => DisplayAnnotationType :: None ,
337
+ snippet:: AnnotationType :: Warning => DisplayAnnotationType :: None ,
338
+ _ => DisplayAnnotationType :: from ( annotation. annotation_type ) ,
339
+ } ;
340
+ match annotation. range {
341
+ ( start, _) if start > line_end_index => true ,
342
+ ( start, end)
343
+ if start >= line_start_index && end <= line_end_index
344
+ || start == line_end_index && end - start <= 1 =>
345
+ {
346
+ let annotation_start_col = char_widths
347
+ . iter ( )
348
+ . take ( start - line_start_index)
349
+ . sum :: < usize > ( )
350
+ - margin_left;
351
+ let annotation_end_col = char_widths
352
+ . iter ( )
353
+ . take ( end - line_start_index)
354
+ . sum :: < usize > ( )
355
+ - margin_left;
356
+ let range = ( annotation_start_col, annotation_end_col) ;
357
+ body. insert (
358
+ body_idx + 1 ,
359
+ DisplayLine :: Source {
360
+ lineno : None ,
361
+ inline_marks : vec ! [ ] ,
362
+ line : DisplaySourceLine :: Annotation {
363
+ annotation : Annotation {
364
+ annotation_type,
365
+ id : None ,
366
+ label : format_label ( Some ( annotation. label ) , None ) ,
422
367
} ,
423
- ) ;
424
- annotation_line_count += 1 ;
425
- }
426
- true
427
- }
428
- ( start, end) if start < line_start_index && end > line_end_index => {
429
- if let DisplayLine :: Source {
430
- ref mut inline_marks,
431
- ..
432
- } = body[ body_idx]
433
- {
434
- inline_marks. push ( DisplayMark {
435
- mark_type : DisplayMarkType :: AnnotationThrough ,
368
+ range,
436
369
annotation_type : DisplayAnnotationType :: from (
437
370
annotation. annotation_type ,
438
371
) ,
439
- } ) ;
440
- }
441
- true
442
- }
443
- ( start, end)
444
- if start < line_start_index
445
- && end >= line_start_index
446
- && end <= line_end_index =>
447
- {
372
+ annotation_part : DisplayAnnotationPart :: Standalone ,
373
+ } ,
374
+ } ,
375
+ ) ;
376
+ annotation_line_count += 1 ;
377
+ false
378
+ }
379
+ ( start, end)
380
+ if start >= line_start_index
381
+ && start <= line_end_index
382
+ && end > line_end_index =>
383
+ {
384
+ if start - line_start_index == 0 {
448
385
if let DisplayLine :: Source {
449
386
ref mut inline_marks,
450
387
..
451
388
} = body[ body_idx]
452
389
{
453
390
inline_marks. push ( DisplayMark {
454
- mark_type : DisplayMarkType :: AnnotationThrough ,
391
+ mark_type : DisplayMarkType :: AnnotationStart ,
455
392
annotation_type : DisplayAnnotationType :: from (
456
393
annotation. annotation_type ,
457
394
) ,
458
395
} ) ;
459
396
}
460
-
461
- let end_mark = char_widths
397
+ } else {
398
+ let annotation_start_col = char_widths
462
399
. iter ( )
463
- . take ( end - line_start_index)
464
- . sum :: < usize > ( )
465
- . saturating_sub ( 1 ) ;
466
- let range = ( end_mark - margin_left, ( end_mark + 1 ) - margin_left) ;
400
+ . take ( start - line_start_index)
401
+ . sum :: < usize > ( ) ;
402
+ let range = ( annotation_start_col, annotation_start_col + 1 ) ;
467
403
body. insert (
468
404
body_idx + 1 ,
469
405
DisplayLine :: Source {
470
406
lineno : None ,
471
- inline_marks : vec ! [ DisplayMark {
472
- mark_type: DisplayMarkType :: AnnotationThrough ,
473
- annotation_type: DisplayAnnotationType :: from(
474
- annotation. annotation_type,
475
- ) ,
476
- } ] ,
407
+ inline_marks : vec ! [ ] ,
477
408
line : DisplaySourceLine :: Annotation {
478
409
annotation : Annotation {
479
- annotation_type,
410
+ annotation_type : DisplayAnnotationType :: None ,
480
411
id : None ,
481
- label : format_label ( Some ( annotation . label ) , None ) ,
412
+ label : vec ! [ ] ,
482
413
} ,
483
414
range,
484
415
annotation_type : DisplayAnnotationType :: from (
485
416
annotation. annotation_type ,
486
417
) ,
487
- annotation_part : DisplayAnnotationPart :: MultilineEnd ,
418
+ annotation_part : DisplayAnnotationPart :: MultilineStart ,
488
419
} ,
489
420
} ,
490
421
) ;
491
422
annotation_line_count += 1 ;
492
- false
493
423
}
494
- _ => true ,
424
+ true
425
+ }
426
+ ( start, end) if start < line_start_index && end > line_end_index => {
427
+ if let DisplayLine :: Source {
428
+ ref mut inline_marks,
429
+ ..
430
+ } = body[ body_idx]
431
+ {
432
+ inline_marks. push ( DisplayMark {
433
+ mark_type : DisplayMarkType :: AnnotationThrough ,
434
+ annotation_type : DisplayAnnotationType :: from (
435
+ annotation. annotation_type ,
436
+ ) ,
437
+ } ) ;
438
+ }
439
+ true
495
440
}
496
- } )
497
- . collect ( ) ;
441
+ ( start, end)
442
+ if start < line_start_index
443
+ && end >= line_start_index
444
+ && end <= line_end_index =>
445
+ {
446
+ if let DisplayLine :: Source {
447
+ ref mut inline_marks,
448
+ ..
449
+ } = body[ body_idx]
450
+ {
451
+ inline_marks. push ( DisplayMark {
452
+ mark_type : DisplayMarkType :: AnnotationThrough ,
453
+ annotation_type : DisplayAnnotationType :: from (
454
+ annotation. annotation_type ,
455
+ ) ,
456
+ } ) ;
457
+ }
458
+
459
+ let end_mark = char_widths
460
+ . iter ( )
461
+ . take ( end - line_start_index)
462
+ . sum :: < usize > ( )
463
+ . saturating_sub ( 1 ) ;
464
+ let range = ( end_mark - margin_left, ( end_mark + 1 ) - margin_left) ;
465
+ body. insert (
466
+ body_idx + 1 ,
467
+ DisplayLine :: Source {
468
+ lineno : None ,
469
+ inline_marks : vec ! [ DisplayMark {
470
+ mark_type: DisplayMarkType :: AnnotationThrough ,
471
+ annotation_type: DisplayAnnotationType :: from(
472
+ annotation. annotation_type,
473
+ ) ,
474
+ } ] ,
475
+ line : DisplaySourceLine :: Annotation {
476
+ annotation : Annotation {
477
+ annotation_type,
478
+ id : None ,
479
+ label : format_label ( Some ( annotation. label ) , None ) ,
480
+ } ,
481
+ range,
482
+ annotation_type : DisplayAnnotationType :: from (
483
+ annotation. annotation_type ,
484
+ ) ,
485
+ annotation_part : DisplayAnnotationPart :: MultilineEnd ,
486
+ } ,
487
+ } ,
488
+ ) ;
489
+ annotation_line_count += 1 ;
490
+ false
491
+ }
492
+ _ => true ,
493
+ }
494
+ } ) ;
498
495
}
499
496
500
497
if slice. fold {
0 commit comments