1- use snippet:: { AnnotationType , Slice , Snippet , TitleAnnotation } ;
1+ use snippet:: { AnnotationType , Slice , Snippet , Annotation } ;
22
33pub struct DisplayList {
44pub body : Vec < DisplayLine > ,
55}
66
77#[ derive( Debug , Clone , PartialEq ) ]
88pub enum DisplayLine {
9- Description {
10- snippet_type : DisplaySnippetType ,
11- id : Option < String > ,
9+ AlignedAnnotation {
1210label : String ,
11+ annotation_type : DisplayAnnotationType ,
12+ } ,
13+ Annotation {
14+ label : String ,
15+ id : Option < String > ,
16+ annotation_type : DisplayAnnotationType ,
1317} ,
1418Origin {
1519path : String ,
@@ -23,21 +27,21 @@ pub enum DisplayLine {
2327content : String ,
2428range : ( usize , usize ) ,
2529} ,
26- Annotation {
30+ SourceAnnotation {
2731inline_marks : Vec < DisplayMark > ,
2832range : ( usize , usize ) ,
2933label : Option < String > ,
3034annotation_type : DisplayAnnotationType ,
35+ annotation_part : DisplayAnnotationPart ,
3136} ,
3237Fold {
3338inline_marks : Vec < DisplayMark > ,
3439} ,
3540}
3641
3742#[ derive( Debug , Clone , PartialEq ) ]
38- pub enum DisplayAnnotationType {
39- Error ,
40- Warning ,
43+ pub enum DisplayAnnotationPart {
44+ Singleline ,
4145MultilineStart ,
4246MultilineEnd ,
4347}
@@ -49,9 +53,11 @@ pub enum DisplayMark {
4953}
5054
5155#[ derive( Debug , Clone , PartialEq ) ]
52- pub enum DisplaySnippetType {
56+ pub enum DisplayAnnotationType {
5357Error ,
5458Warning ,
59+ Note ,
60+ Help ,
5561}
5662
5763#[ derive( Debug , Clone , PartialEq ) ]
@@ -62,15 +68,23 @@ pub enum DisplayHeaderType {
6268
6369// Formatting
6470
65- fn format_title ( annotation : & TitleAnnotation ) ->DisplayLine {
71+ fn format_title ( annotation : & Annotation ) ->DisplayLine {
6672let label = annotation. label . clone ( ) . unwrap_or ( "" . to_string ( ) ) ;
67- DisplayLine :: Description {
68- snippet_type : DisplaySnippetType :: from ( annotation. annotation_type ) ,
73+ DisplayLine :: Annotation {
74+ annotation_type : DisplayAnnotationType :: from ( annotation. annotation_type ) ,
6975id : annotation. id . clone ( ) ,
7076 label,
7177}
7278}
7379
80+ fn format_annotation ( annotation : & Annotation ) ->DisplayLine {
81+ let label = annotation. label . clone ( ) . unwrap_or ( "" . to_string ( ) ) ;
82+ DisplayLine :: AlignedAnnotation {
83+ annotation_type : DisplayAnnotationType :: from ( annotation. annotation_type ) ,
84+ label,
85+ }
86+ }
87+
7488fn format_slice ( slice : & Slice , is_first : bool ) ->Vec < DisplayLine > {
7589let mut body =format_body ( slice) ;
7690let mut result =vec ! [ ] ;
@@ -132,7 +146,7 @@ fn fold_body(body: &[DisplayLine]) -> Vec<DisplayLine> {
132146
133147while idx < body. len ( ) {
134148match body[ idx] {
135- DisplayLine :: Annotation {
149+ DisplayLine :: SourceAnnotation {
136150ref inline_marks, ..
137151} =>{
138152if no_annotation_lines_counter >10 {
@@ -204,13 +218,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
204218let range =( start - line_start, end - line_start) ;
205219 body. insert (
206220 body_idx +1 ,
207- DisplayLine :: Annotation {
221+ DisplayLine :: SourceAnnotation {
208222inline_marks : vec ! [ ] ,
209223 range,
210224label : Some ( annotation. label . clone ( ) ) ,
211225annotation_type : DisplayAnnotationType :: from (
212226 annotation. annotation_type ,
213227) ,
228+ annotation_part : DisplayAnnotationPart :: Singleline ,
214229} ,
215230) ;
216231 annotation_line_count +=1 ;
@@ -229,11 +244,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
229244let range =( start - line_start, start - line_start +1 ) ;
230245 body. insert (
231246 body_idx +1 ,
232- DisplayLine :: Annotation {
247+ DisplayLine :: SourceAnnotation {
233248inline_marks : vec ! [ ] ,
234249 range,
235250label : None ,
236- annotation_type : DisplayAnnotationType :: MultilineStart ,
251+ annotation_type : DisplayAnnotationType :: from (
252+ annotation. annotation_type ,
253+ ) ,
254+ annotation_part : DisplayAnnotationPart :: MultilineStart ,
237255} ,
238256) ;
239257 annotation_line_count +=1 ;
@@ -261,11 +279,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
261279let range =( end - line_start, end - line_start +1 ) ;
262280 body. insert (
263281 body_idx +1 ,
264- DisplayLine :: Annotation {
282+ DisplayLine :: SourceAnnotation {
265283inline_marks : vec ! [ DisplayMark :: AnnotationThrough ] ,
266284 range,
267285label : Some ( annotation. label . clone ( ) ) ,
268- annotation_type : DisplayAnnotationType :: MultilineEnd ,
286+ annotation_type : DisplayAnnotationType :: from (
287+ annotation. annotation_type ,
288+ ) ,
289+ annotation_part : DisplayAnnotationPart :: MultilineEnd ,
269290} ,
270291) ;
271292 annotation_line_count +=1 ;
@@ -299,6 +320,9 @@ impl From<Snippet> for DisplayList {
299320 body. append ( & mut format_slice ( & slice, slice_idx ==0 ) ) ;
300321 slice_idx +=1 ;
301322}
323+ if let Some ( annotation) = snippet. footer {
324+ body. push ( format_annotation ( & annotation) ) ;
325+ }
302326
303327Self { body}
304328}
@@ -309,15 +333,8 @@ impl From<AnnotationType> for DisplayAnnotationType {
309333match at{
310334AnnotationType :: Error =>DisplayAnnotationType :: Error ,
311335AnnotationType :: Warning =>DisplayAnnotationType :: Warning ,
312- }
313- }
314- }
315-
316- impl From < AnnotationType > for DisplaySnippetType {
317- fn from ( at : AnnotationType ) ->Self {
318- match at{
319- AnnotationType :: Error =>DisplaySnippetType :: Error ,
320- AnnotationType :: Warning =>DisplaySnippetType :: Warning ,
336+ AnnotationType :: Note =>DisplayAnnotationType :: Note ,
337+ AnnotationType :: Help =>DisplayAnnotationType :: Help ,
321338}
322339}
323340}