2016-04-20 13:52:31 -05:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Code for annotating snippets.
|
|
|
|
|
2016-07-12 14:18:16 -05:00
|
|
|
use syntax_pos::{Span, FileMap};
|
2016-06-21 17:08:13 -05:00
|
|
|
use CodeMapper;
|
2016-04-20 13:52:31 -05:00
|
|
|
use std::rc::Rc;
|
2016-07-11 15:02:03 -05:00
|
|
|
use {Level};
|
2016-04-20 13:52:31 -05:00
|
|
|
|
2016-06-23 14:19:40 -05:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum FormatMode {
|
|
|
|
NewErrorFormat,
|
|
|
|
OriginalErrorFormat,
|
|
|
|
EnvironmentSelected
|
|
|
|
}
|
|
|
|
|
2016-04-28 18:39:59 -05:00
|
|
|
#[derive(Clone)]
|
2016-04-20 13:52:31 -05:00
|
|
|
pub struct SnippetData {
|
2016-06-21 17:08:13 -05:00
|
|
|
codemap: Rc<CodeMapper>,
|
2016-04-20 13:52:31 -05:00
|
|
|
files: Vec<FileInfo>,
|
2016-06-23 14:19:40 -05:00
|
|
|
format_mode: FormatMode,
|
2016-04-20 13:52:31 -05:00
|
|
|
}
|
|
|
|
|
2016-04-28 18:39:59 -05:00
|
|
|
#[derive(Clone)]
|
2016-04-20 13:52:31 -05:00
|
|
|
pub struct FileInfo {
|
|
|
|
file: Rc<FileMap>,
|
|
|
|
|
|
|
|
/// The "primary file", if any, gets a `-->` marker instead of
|
|
|
|
/// `>>>`, and has a line-number/column printed and not just a
|
|
|
|
/// filename. It appears first in the listing. It is known to
|
|
|
|
/// contain at least one primary span, though primary spans (which
|
|
|
|
/// are designated with `^^^`) may also occur in other files.
|
|
|
|
primary_span: Option<Span>,
|
|
|
|
|
|
|
|
lines: Vec<Line>,
|
2016-06-23 14:19:40 -05:00
|
|
|
|
|
|
|
/// The type of error format to render. We keep it here so that
|
|
|
|
/// it's easy to configure for both tests and regular usage
|
|
|
|
format_mode: FormatMode,
|
2016-04-20 13:52:31 -05:00
|
|
|
}
|
|
|
|
|
2016-07-11 15:02:03 -05:00
|
|
|
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
|
|
|
pub struct Line {
|
|
|
|
pub line_index: usize,
|
|
|
|
pub annotations: Vec<Annotation>,
|
2016-04-20 13:52:31 -05:00
|
|
|
}
|
|
|
|
|
2016-05-02 12:05:14 -05:00
|
|
|
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
|
2016-07-11 15:02:03 -05:00
|
|
|
pub struct Annotation {
|
2016-04-20 13:52:31 -05:00
|
|
|
/// Start column, 0-based indexing -- counting *characters*, not
|
|
|
|
/// utf-8 bytes. Note that it is important that this field goes
|
|
|
|
/// first, so that when we sort, we sort orderings by start
|
|
|
|
/// column.
|
2016-07-11 15:02:03 -05:00
|
|
|
pub start_col: usize,
|
2016-04-20 13:52:31 -05:00
|
|
|
|
2016-04-26 11:33:38 -05:00
|
|
|
/// End column within the line (exclusive)
|
2016-07-11 15:02:03 -05:00
|
|
|
pub end_col: usize,
|
2016-04-20 13:52:31 -05:00
|
|
|
|
|
|
|
/// Is this annotation derived from primary span
|
2016-07-11 15:02:03 -05:00
|
|
|
pub is_primary: bool,
|
2016-04-20 13:52:31 -05:00
|
|
|
|
2016-05-16 14:39:25 -05:00
|
|
|
/// Is this a large span minimized down to a smaller span
|
2016-07-11 15:02:03 -05:00
|
|
|
pub is_minimized: bool,
|
2016-05-16 14:39:25 -05:00
|
|
|
|
2016-04-20 13:52:31 -05:00
|
|
|
/// Optional label to display adjacent to the annotation.
|
2016-07-11 15:02:03 -05:00
|
|
|
pub label: Option<String>,
|
2016-04-20 13:52:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct StyledString {
|
|
|
|
pub text: String,
|
|
|
|
pub style: Style,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
|
|
pub enum Style {
|
2016-07-11 15:02:03 -05:00
|
|
|
HeaderMsg,
|
2016-04-20 13:52:31 -05:00
|
|
|
FileNameStyle,
|
|
|
|
LineAndColumn,
|
|
|
|
LineNumber,
|
|
|
|
Quotation,
|
|
|
|
UnderlinePrimary,
|
|
|
|
UnderlineSecondary,
|
|
|
|
LabelPrimary,
|
|
|
|
LabelSecondary,
|
2016-07-11 15:02:03 -05:00
|
|
|
OldSchoolNoteText,
|
|
|
|
OldSchoolNote,
|
2016-04-20 13:52:31 -05:00
|
|
|
NoStyle,
|
2016-07-11 15:02:03 -05:00
|
|
|
ErrorCode,
|
|
|
|
Level(Level),
|
2016-07-12 14:18:16 -05:00
|
|
|
}
|