extern crate termcolor;
extern crate codemap;
use codemap::Span;
mod lock;
mod snippet;
mod styled_buffer;
mod emitter;
pub use emitter::{ ColorConfig, Emitter };
use termcolor::{ ColorSpec, Color };
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Diagnostic {
pub level: Level,
pub message: String,
pub code: Option<String>,
pub spans: Vec<SpanLabel>,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Level {
Bug,
Error,
Warning,
Note,
Help,
}
impl ::std::fmt::Display for Level {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
self.to_str().fmt(f)
}
}
impl Level {
fn color(self) -> ColorSpec {
let mut spec = ColorSpec::new();
use self::Level::*;
match self {
Bug | Error => {
spec.set_fg(Some(Color::Red))
.set_intense(true);
}
Warning => {
spec.set_fg(Some(Color::Yellow))
.set_intense(cfg!(windows));
}
Note => {
spec.set_fg(Some(Color::Green))
.set_intense(true);
}
Help => {
spec.set_fg(Some(Color::Cyan))
.set_intense(true);
}
}
spec
}
pub fn to_str(self) -> &'static str {
use self::Level::*;
match self {
Bug => "error: internal compiler error",
Error => "error",
Warning => "warning",
Note => "note",
Help => "help",
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SpanLabel {
pub span: Span,
pub label: Option<String>,
pub style: SpanStyle,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum SpanStyle {
Primary,
Secondary,
}