Update to codespan-reporting 0.9

This commit is contained in:
David Tolnay 2020-03-18 14:02:01 -07:00
parent 6dfa3b0a7c
commit e2e7bc3c9e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
8 changed files with 19 additions and 55 deletions

2
BUCK
View File

@ -7,7 +7,6 @@ rust_library(
":macro",
"//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan",
"//third-party:codespan-reporting",
"//third-party:link-cplusplus",
"//third-party:proc-macro2",
@ -26,7 +25,6 @@ rust_binary(
},
deps = [
"//third-party:anyhow",
"//third-party:codespan",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
"//third-party:quote",

2
BUILD
View File

@ -10,7 +10,6 @@ rust_library(
":cxxbridge-macro",
"//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan",
"//third-party:codespan-reporting",
"//third-party:link-cplusplus",
"//third-party:proc-macro2",
@ -27,7 +26,6 @@ rust_binary(
visibility = ["//visibility:public"],
deps = [
"//third-party:anyhow",
"//third-party:codespan",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
"//third-party:quote",

View File

@ -17,8 +17,7 @@ travis-ci = { repository = "dtolnay/cxx" }
[dependencies]
anyhow = "1.0"
cc = "1.0.49"
codespan = "0.7"
codespan-reporting = "0.7"
codespan-reporting = "0.9"
cxxbridge-macro = { version = "=0.2.0", path = "macro" }
link-cplusplus = "1.0"
proc-macro2 = { version = "1.0", features = ["span-locations"] }

View File

@ -16,8 +16,7 @@ travis-ci = { repository = "dtolnay/cxx" }
[dependencies]
anyhow = "1.0"
codespan = "0.7"
codespan-reporting = "0.7"
codespan-reporting = "0.9"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
structopt = "0.3"

View File

@ -1,8 +1,8 @@
use crate::gen::Error;
use crate::syntax;
use anyhow::anyhow;
use codespan::{FileId, Files};
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColor};
use codespan_reporting::term::{self, Config};
use std::io::Write;
@ -46,32 +46,30 @@ fn display_syn_error(stderr: &mut dyn WriteColor, path: &Path, source: &str, err
}
end_offset += end.column;
let mut files = Files::new();
let mut files = SimpleFiles::new();
let file = files.add(path.to_string_lossy(), source);
let range = start_offset as u32..end_offset as u32;
let diagnostic = diagnose(file, range, error);
let diagnostic = diagnose(file, start_offset..end_offset, error);
let config = Config::default();
let _ = term::emit(stderr, &config, &files, &diagnostic);
}
fn diagnose(file: FileId, range: Range<u32>, error: syn::Error) -> Diagnostic {
fn diagnose(file: usize, range: Range<usize>, error: syn::Error) -> Diagnostic<usize> {
let message = error.to_string();
let info = syntax::error::ERRORS
.iter()
.find(|e| message.contains(e.msg));
let mut diagnostic = if let Some(info) = info {
let label = Label::new(file, range, info.label.unwrap_or(&message));
let mut diagnostic = Diagnostic::new_error(&message, label);
if let Some(note) = info.note {
diagnostic = diagnostic.with_notes(vec![note.to_owned()]);
}
diagnostic
let mut diagnostic = Diagnostic::error().with_message(&message);
let mut label = Label::primary(file, range);
if let Some(info) = info {
label.message = info.label.map_or(message, str::to_owned);
diagnostic.labels.push(label);
diagnostic.notes.extend(info.note.map(str::to_owned));
} else {
let label = Label::new(file, range, &message);
Diagnostic::new_error(&message, label)
};
label.message = message;
diagnostic.labels.push(label);
}
diagnostic.code = Some("cxxbridge".to_owned());
diagnostic
}

10
third-party/BUCK vendored
View File

@ -29,19 +29,11 @@ rust_library(
],
)
rust_library(
name = "codespan",
srcs = glob(["vendor/codespan-0.7.0/src/**"]),
visibility = ["PUBLIC"],
deps = [":unicode-segmentation"],
)
rust_library(
name = "codespan-reporting",
srcs = glob(["vendor/codespan-reporting-0.7.0/src/**"]),
srcs = glob(["vendor/codespan-reporting-0.9.0/src/**"]),
visibility = ["PUBLIC"],
deps = [
":codespan",
":termcolor",
":unicode-width",
],

10
third-party/BUILD vendored
View File

@ -34,19 +34,11 @@ rust_library(
],
)
rust_library(
name = "codespan",
srcs = glob(["vendor/codespan-0.7.0/src/**"]),
visibility = ["//visibility:public"],
deps = [":unicode-segmentation"],
)
rust_library(
name = "codespan-reporting",
srcs = glob(["vendor/codespan-reporting-0.7.0/src/**"]),
srcs = glob(["vendor/codespan-reporting-0.9.0/src/**"]),
visibility = ["//visibility:public"],
deps = [
":codespan",
":termcolor",
":unicode-width",
],

16
third-party/Cargo.lock generated vendored
View File

@ -53,22 +53,12 @@ dependencies = [
"vec_map",
]
[[package]]
name = "codespan"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21094c000d5db8035900662bbfddec754e79f795324254ac0817f36e5ccfc3f5"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "codespan-reporting"
version = "0.7.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "657b2c99e1f17bc3e5153808d9f704c8ba6171c3fe45e69fde26e2876156938b"
checksum = "7606d610349258b637bb639f7565bb7ee5fd6114130d2af59d0f39154e92426a"
dependencies = [
"codespan",
"termcolor",
"unicode-width",
]
@ -79,7 +69,6 @@ version = "0.2.0"
dependencies = [
"anyhow",
"cc",
"codespan",
"codespan-reporting",
"cxx-test-suite",
"cxxbridge-macro",
@ -104,7 +93,6 @@ name = "cxxbridge-cmd"
version = "0.2.0"
dependencies = [
"anyhow",
"codespan",
"codespan-reporting",
"proc-macro2",
"quote",