]> git.lizzy.rs Git - rust.git/blob - src/librustc_errors/snippet.rs
run rustfmt on librustc_errors folder
[rust.git] / src / librustc_errors / snippet.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Code for annotating snippets.
12
13 use syntax_pos::{Span, FileMap};
14 use CodeMapper;
15 use std::rc::Rc;
16 use Level;
17
18 #[derive(Clone)]
19 pub struct SnippetData {
20     codemap: Rc<CodeMapper>,
21     files: Vec<FileInfo>,
22 }
23
24 #[derive(Clone)]
25 pub struct FileInfo {
26     file: Rc<FileMap>,
27
28     /// The "primary file", if any, gets a `-->` marker instead of
29     /// `>>>`, and has a line-number/column printed and not just a
30     /// filename.  It appears first in the listing. It is known to
31     /// contain at least one primary span, though primary spans (which
32     /// are designated with `^^^`) may also occur in other files.
33     primary_span: Option<Span>,
34
35     lines: Vec<Line>,
36 }
37
38 #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
39 pub struct Line {
40     pub line_index: usize,
41     pub annotations: Vec<Annotation>,
42 }
43
44 #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
45 pub struct Annotation {
46     /// Start column, 0-based indexing -- counting *characters*, not
47     /// utf-8 bytes. Note that it is important that this field goes
48     /// first, so that when we sort, we sort orderings by start
49     /// column.
50     pub start_col: usize,
51
52     /// End column within the line (exclusive)
53     pub end_col: usize,
54
55     /// Is this annotation derived from primary span
56     pub is_primary: bool,
57
58     /// Is this a large span minimized down to a smaller span
59     pub is_minimized: bool,
60
61     /// Optional label to display adjacent to the annotation.
62     pub label: Option<String>,
63 }
64
65 #[derive(Debug)]
66 pub struct StyledString {
67     pub text: String,
68     pub style: Style,
69 }
70
71 #[derive(Copy, Clone, Debug, PartialEq)]
72 pub enum Style {
73     HeaderMsg,
74     FileNameStyle,
75     LineAndColumn,
76     LineNumber,
77     Quotation,
78     UnderlinePrimary,
79     UnderlineSecondary,
80     LabelPrimary,
81     LabelSecondary,
82     OldSchoolNoteText,
83     OldSchoolNote,
84     NoStyle,
85     ErrorCode,
86     Level(Level),
87 }