1
- use snippet:: { AnnotationType , Slice , Snippet , TitleAnnotation } ;
1
+ use snippet:: { AnnotationType , Slice , Snippet , Annotation } ;
2
2
3
3
pub struct DisplayList {
4
4
pub body : Vec < DisplayLine > ,
5
5
}
6
6
7
7
#[ derive( Debug , Clone , PartialEq ) ]
8
8
pub enum DisplayLine {
9
- Description {
10
- snippet_type : DisplaySnippetType ,
11
- id : Option < String > ,
9
+ AlignedAnnotation {
12
10
label : String ,
11
+ annotation_type : DisplayAnnotationType ,
12
+ } ,
13
+ Annotation {
14
+ label : String ,
15
+ id : Option < String > ,
16
+ annotation_type : DisplayAnnotationType ,
13
17
} ,
14
18
Origin {
15
19
path : String ,
@@ -23,21 +27,21 @@ pub enum DisplayLine {
23
27
content : String ,
24
28
range : ( usize , usize ) ,
25
29
} ,
26
- Annotation {
30
+ SourceAnnotation {
27
31
inline_marks : Vec < DisplayMark > ,
28
32
range : ( usize , usize ) ,
29
33
label : Option < String > ,
30
34
annotation_type : DisplayAnnotationType ,
35
+ annotation_part : DisplayAnnotationPart ,
31
36
} ,
32
37
Fold {
33
38
inline_marks : Vec < DisplayMark > ,
34
39
} ,
35
40
}
36
41
37
42
#[ derive( Debug , Clone , PartialEq ) ]
38
- pub enum DisplayAnnotationType {
39
- Error ,
40
- Warning ,
43
+ pub enum DisplayAnnotationPart {
44
+ Singleline ,
41
45
MultilineStart ,
42
46
MultilineEnd ,
43
47
}
@@ -49,9 +53,11 @@ pub enum DisplayMark {
49
53
}
50
54
51
55
#[ derive( Debug , Clone , PartialEq ) ]
52
- pub enum DisplaySnippetType {
56
+ pub enum DisplayAnnotationType {
53
57
Error ,
54
58
Warning ,
59
+ Note ,
60
+ Help ,
55
61
}
56
62
57
63
#[ derive( Debug , Clone , PartialEq ) ]
@@ -62,15 +68,23 @@ pub enum DisplayHeaderType {
62
68
63
69
// Formatting
64
70
65
- fn format_title ( annotation : & TitleAnnotation ) -> DisplayLine {
71
+ fn format_title ( annotation : & Annotation ) -> DisplayLine {
66
72
let 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 ) ,
69
75
id : annotation. id . clone ( ) ,
70
76
label,
71
77
}
72
78
}
73
79
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
+
74
88
fn format_slice ( slice : & Slice , is_first : bool ) -> Vec < DisplayLine > {
75
89
let mut body = format_body ( slice) ;
76
90
let mut result = vec ! [ ] ;
@@ -132,7 +146,7 @@ fn fold_body(body: &[DisplayLine]) -> Vec<DisplayLine> {
132
146
133
147
while idx < body. len ( ) {
134
148
match body[ idx] {
135
- DisplayLine :: Annotation {
149
+ DisplayLine :: SourceAnnotation {
136
150
ref inline_marks, ..
137
151
} => {
138
152
if no_annotation_lines_counter > 10 {
@@ -204,13 +218,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
204
218
let range = ( start - line_start, end - line_start) ;
205
219
body. insert (
206
220
body_idx + 1 ,
207
- DisplayLine :: Annotation {
221
+ DisplayLine :: SourceAnnotation {
208
222
inline_marks : vec ! [ ] ,
209
223
range,
210
224
label : Some ( annotation. label . clone ( ) ) ,
211
225
annotation_type : DisplayAnnotationType :: from (
212
226
annotation. annotation_type ,
213
227
) ,
228
+ annotation_part : DisplayAnnotationPart :: Singleline ,
214
229
} ,
215
230
) ;
216
231
annotation_line_count += 1 ;
@@ -229,11 +244,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
229
244
let range = ( start - line_start, start - line_start + 1 ) ;
230
245
body. insert (
231
246
body_idx + 1 ,
232
- DisplayLine :: Annotation {
247
+ DisplayLine :: SourceAnnotation {
233
248
inline_marks : vec ! [ ] ,
234
249
range,
235
250
label : None ,
236
- annotation_type : DisplayAnnotationType :: MultilineStart ,
251
+ annotation_type : DisplayAnnotationType :: from (
252
+ annotation. annotation_type ,
253
+ ) ,
254
+ annotation_part : DisplayAnnotationPart :: MultilineStart ,
237
255
} ,
238
256
) ;
239
257
annotation_line_count += 1 ;
@@ -261,11 +279,14 @@ fn format_body(slice: &Slice) -> Vec<DisplayLine> {
261
279
let range = ( end - line_start, end - line_start + 1 ) ;
262
280
body. insert (
263
281
body_idx + 1 ,
264
- DisplayLine :: Annotation {
282
+ DisplayLine :: SourceAnnotation {
265
283
inline_marks : vec ! [ DisplayMark :: AnnotationThrough ] ,
266
284
range,
267
285
label : Some ( annotation. label . clone ( ) ) ,
268
- annotation_type : DisplayAnnotationType :: MultilineEnd ,
286
+ annotation_type : DisplayAnnotationType :: from (
287
+ annotation. annotation_type ,
288
+ ) ,
289
+ annotation_part : DisplayAnnotationPart :: MultilineEnd ,
269
290
} ,
270
291
) ;
271
292
annotation_line_count += 1 ;
@@ -299,6 +320,9 @@ impl From<Snippet> for DisplayList {
299
320
body. append ( & mut format_slice ( & slice, slice_idx == 0 ) ) ;
300
321
slice_idx += 1 ;
301
322
}
323
+ if let Some ( annotation) = snippet. footer {
324
+ body. push ( format_annotation ( & annotation) ) ;
325
+ }
302
326
303
327
Self { body }
304
328
}
@@ -309,15 +333,8 @@ impl From<AnnotationType> for DisplayAnnotationType {
309
333
match at {
310
334
AnnotationType :: Error => DisplayAnnotationType :: Error ,
311
335
AnnotationType :: 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 ,
321
338
}
322
339
}
323
340
}
0 commit comments