|
| 1 | +//! display_list module stores the output model for the snippet. |
| 2 | +//! |
| 3 | +//! `DisplayList` is a central structure in the crate, which contains |
| 4 | +//! the structured list of lines to be displayed. |
| 5 | +//! |
| 6 | +//! It is made of two types of lines: `Source` and `Raw`. All `Source` lines |
| 7 | +//! are structured using four columns: |
| 8 | +//! |
| 9 | +//! ```text |
| 10 | +//! /------------ (1) Line number column. |
| 11 | +//! | /--------- (2) Line number column delimiter. |
| 12 | +//! | | /------- (3) Inline marks column. |
| 13 | +//! | | | /--- (4) Content column with the source and annotations for slices. |
| 14 | +//! | | | | |
| 15 | +//! ============================================================================= |
| 16 | +//! error[E0308]: mismatched types |
| 17 | +//! --> src/format.rs:51:5 |
| 18 | +//! | |
| 19 | +//! 151 | / fn test() -> String { |
| 20 | +//! 152 | | return "test"; |
| 21 | +//! 153 | | } |
| 22 | +//! | |___^ error: expected `String`, for `&str`. |
| 23 | +//! | |
| 24 | +//! ``` |
| 25 | +//! |
| 26 | +//! The first two lines of the example above are `Raw` lines, while the rest |
| 27 | +//! are `Source` lines. |
| 28 | +//! |
| 29 | +//! `DisplayList` does not store column alignment information, and those are |
| 30 | +//! only calculated by the `DisplayListFormatter` using information such as |
| 31 | +//! styling. |
| 32 | +//! |
| 33 | +//! The above snippet has been built out of the following structure: |
| 34 | +//! |
| 35 | +//! ``` |
| 36 | +//! use annotate_snippets::display_list::*; |
| 37 | +//! |
| 38 | +//! let dl = DisplayList { |
| 39 | +//! body: vec![ |
| 40 | +//! DisplayLine::Raw(DisplayRawLine::Annotation { |
| 41 | +//! annotation: Annotation { |
| 42 | +//! annotation_type: DisplayAnnotationType::Error, |
| 43 | +//! id: Some("E0308".to_string()), |
| 44 | +//! label: vec![ |
| 45 | +//! DisplayTextFragment { |
| 46 | +//! content: "mismatched types".to_string(), |
| 47 | +//! style: DisplayTextStyle::Regular, |
| 48 | +//! } |
| 49 | +//! ] |
| 50 | +//! }, |
| 51 | +//! source_aligned: false, |
| 52 | +//! continuation: false, |
| 53 | +//! }), |
| 54 | +//! DisplayLine::Raw(DisplayRawLine::Origin { |
| 55 | +//! path: "src/format.rs".to_string(), |
| 56 | +//! pos: Some((51, 5)), |
| 57 | +//! header_type: DisplayHeaderType::Initial, |
| 58 | +//! }), |
| 59 | +//! DisplayLine::Source { |
| 60 | +//! lineno: Some(151), |
| 61 | +//! inline_marks: vec![ |
| 62 | +//! DisplayMark { |
| 63 | +//! mark_type: DisplayMarkType::AnnotationStart, |
| 64 | +//! annotation_type: DisplayAnnotationType::Error, |
| 65 | +//! } |
| 66 | +//! ], |
| 67 | +//! line: DisplaySourceLine::Content { |
| 68 | +//! text: " fn test() -> String {".to_string(), |
| 69 | +//! range: (0, 24) |
| 70 | +//! } |
| 71 | +//! }, |
| 72 | +//! DisplayLine::Source { |
| 73 | +//! lineno: Some(152), |
| 74 | +//! inline_marks: vec![ |
| 75 | +//! DisplayMark { |
| 76 | +//! mark_type: DisplayMarkType::AnnotationThrough, |
| 77 | +//! annotation_type: DisplayAnnotationType::Error, |
| 78 | +//! } |
| 79 | +//! ], |
| 80 | +//! line: DisplaySourceLine::Content { |
| 81 | +//! text: " return \"test\";".to_string(), |
| 82 | +//! range: (25, 46) |
| 83 | +//! } |
| 84 | +//! }, |
| 85 | +//! DisplayLine::Source { |
| 86 | +//! lineno: Some(153), |
| 87 | +//! inline_marks: vec![ |
| 88 | +//! DisplayMark { |
| 89 | +//! mark_type: DisplayMarkType::AnnotationThrough, |
| 90 | +//! annotation_type: DisplayAnnotationType::Error, |
| 91 | +//! } |
| 92 | +//! ], |
| 93 | +//! line: DisplaySourceLine::Content { |
| 94 | +//! text: " }".to_string(), |
| 95 | +//! range: (47, 51) |
| 96 | +//! } |
| 97 | +//! }, |
| 98 | +//! DisplayLine::Source { |
| 99 | +//! lineno: None, |
| 100 | +//! inline_marks: vec![], |
| 101 | +//! line: DisplaySourceLine::Annotation { |
| 102 | +//! annotation: Annotation { |
| 103 | +//! annotation_type: DisplayAnnotationType::Error, |
| 104 | +//! id: None, |
| 105 | +//! label: vec![ |
| 106 | +//! DisplayTextFragment { |
| 107 | +//! content: "expected `String`, for `&str`.".to_string(), |
| 108 | +//! style: DisplayTextStyle::Regular, |
| 109 | +//! } |
| 110 | +//! ] |
| 111 | +//! }, |
| 112 | +//! range: (3, 4), |
| 113 | +//! annotation_type: DisplayAnnotationType::Error, |
| 114 | +//! annotation_part: DisplayAnnotationPart::MultilineEnd, |
| 115 | +//! } |
| 116 | +//! |
| 117 | +//! } |
| 118 | +//! ] |
| 119 | +//! }; |
| 120 | +//! ``` |
1 | 121 | mod from_snippet;
|
2 | 122 | mod structs;
|
3 | 123 |
|
|
0 commit comments