@@ -199,139 +199,143 @@ fn format_body(slice: &snippet::Slice, has_footer: bool) -> Vec<DisplayLine> {
199199let mut annotations = slice. annotations . clone ( ) ;
200200for idxin 0 ..body. len ( ) {
201201let ( 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 ,
223232} ,
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 ,
225285annotation_type : DisplayAnnotationType :: from (
226286 annotation. annotation_type ,
227287) ,
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 =>{
237293if let DisplayLine :: Source {
238294ref mut inline_marks,
239295 ..
240296} = body[ body_idx]
241297{
242298 inline_marks. push ( DisplayMark {
243- mark_type : DisplayMarkType :: AnnotationStart ,
299+ mark_type : DisplayMarkType :: AnnotationThrough ,
244300annotation_type : DisplayAnnotationType :: from (
245301 annotation. annotation_type ,
246302) ,
247303} ) ;
248304}
249- } else {
250- let range =( start - line_start, start - line_start +1 ) ;
305+ let range =( end - line_start, end - line_start +1 ) ;
251306 body. insert (
252307 body_idx +1 ,
253308DisplayLine :: Source {
254309lineno : 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+ ] ,
256318line : DisplaySourceLine :: Annotation {
257319annotation : Annotation {
258- annotation_type : DisplayAnnotationType :: None ,
320+ annotation_type,
259321id : None ,
260- label : vec ! [ ] ,
322+ label : format_label ( Some ( & annotation . label ) , None ) ,
261323} ,
262324 range,
263325annotation_type : DisplayAnnotationType :: from (
264326 annotation. annotation_type ,
265327) ,
266- annotation_part : DisplayAnnotationPart :: MultilineStart ,
328+ annotation_part : DisplayAnnotationPart :: MultilineEnd ,
267329} ,
268330} ,
269331) ;
270332 annotation_line_count +=1 ;
333+ false
271334}
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 ,
288336}
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 ( ) ;
335339}
336340
337341if slice. fold {