1 unstable release
Uses old Rust 2015
0.1.0 | May 4, 2023 |
---|
#635 in Command-line interface
86KB
1.5K
SLoC
CodeMap2 Diagnostic
A Rust library for formatting compiler error messages, extracted from rustc and built on the types from the codemap crate.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
A library for formatting compiler error messages, extracted from rustc and built on the types from the codemap crate.
Example
extern crate codemap2;
extern crate codemap2_diagnostic;
use codemap2::{CodeMap, DefaultFileData};
use codemap2_diagnostic::{ Level, SpanLabel, SpanStyle, Diagnostic, ColorConfig, Emitter };
fn main() {
let code = "foo + bar";
let mut codemap = CodeMap::new();
let file_span = codemap.add_file(DefaultFileData::new("test.rs".to_owned(), code.to_owned())).span;
let name_span = file_span.subspan(0, 3);
let label = SpanLabel {
span: name_span,
style: SpanStyle::Primary,
label: Some("undefined variable".to_owned())
};
let d = Diagnostic {
level: Level::Error,
message: "cannot find value `foo` in this scope".to_owned(),
code: Some("C000".to_owned()),
spans: vec![label]
};
let mut emitter = Emitter::stderr(ColorConfig::Always, Some(&codemap));
emitter.emit(&[d]);
}
Dependencies
~0.2–7MB
~42K SLoC