Skip to content

Commit db97fa6

Browse files
bors[bot]Markus WesterlindMarwes
authored
Merge #849
849: feat: Update to codespan_reporting 0.9 r=Marwes a=Marwes Co-authored-by: Markus Westerlind <[email protected]> Co-authored-by: Markus Westerlind <[email protected]>
2 parents 989c6c8 + d1626d8 commit db97fa6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1337
-657
lines changed

Cargo.lock

Lines changed: 516 additions & 362 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ log = "0.4"
3838
quick-error = "1.0.0"
3939
collect-mac = "0.1.0"
4040
either = "1.0.0"
41-
itertools = "0.8"
41+
itertools = "0.9"
4242
futures = { version = "0.3.1", features = ["thread-pool"] }
43-
codespan = "0.3"
44-
codespan-reporting = "0.3"
43+
codespan = "0.9"
44+
codespan-reporting = "0.9"
4545
pin-project = "0.4"
4646
salsa = { version = "0.14.0", package = "gluon-salsa" }
4747

@@ -61,7 +61,7 @@ native-tls = { version = "0.2", optional = true }
6161
tokio-tls = { version = "0.3", optional = true }
6262

6363
# Crates used in testing
64-
compiletest_rs = { version = "0.3.23", optional = true }
64+
compiletest_rs = { version = "0.5", optional = true }
6565

6666
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
6767
rand = { version = "0.7", optional = true }
@@ -70,7 +70,7 @@ rand_xorshift = { version = "0.2", optional = true }
7070
[build-dependencies]
7171
gluon_base = { path = "base", version = "0.15.1" } # GLUON
7272

73-
itertools = "0.8"
73+
itertools = "0.9"
7474
little-skeptic = { version = "0.15.0", optional = true }
7575
walkdir = "2"
7676

@@ -80,6 +80,7 @@ collect-mac = "0.1.0"
8080
env_logger = "0.7"
8181
failure = "0.1"
8282
failure_derive = "0.1"
83+
insta = "0.16"
8384
pretty_assertions = "0.6"
8485
structopt = "0.3"
8586
tempfile = "3.0.4"
@@ -93,7 +94,7 @@ serde_derive_state = { version = "0.4.0" }
9394
serde_json = "1.0.0"
9495
bincode = "1"
9596

96-
pulldown-cmark = "0.6"
97+
pulldown-cmark = "0.7"
9798

9899
gluon_completion = { path = "completion", version = "0.15.1" } # GLUON
99100
gluon_codegen = { path = "codegen", version = "0.15.1" } # GLUON
@@ -147,4 +148,4 @@ features = ["docs_rs"]
147148
# debug = 2
148149
#
149150
# [profile.release]
150-
# debug = 2
151+
# debug = 2

base/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ pretty = "0.10"
2525
smallvec = "0.6"
2626
collect-mac = "0.1.0"
2727
anymap = "0.12.0"
28-
itertools = "0.8"
28+
itertools = "0.9"
2929
ordered-float = "1"
30-
codespan = "0.3"
31-
codespan-reporting = "0.3"
30+
codespan = "0.9"
31+
codespan-reporting = "0.9"
3232
either = "1"
3333
vec_map = "0.8"
3434
typed-arena = "1"
@@ -41,7 +41,7 @@ serde_derive = { version = "1.0.0", optional = true }
4141
serde_derive_state = { version = "0.4.0", optional = true }
4242

4343
# Crates used in testing
44-
compiletest_rs = { version = "0.3.23", optional = true }
44+
compiletest_rs = { version = "0.5", optional = true }
4545

4646
[dev-dependencies]
4747
env_logger = "0.7"

base/src/error.rs

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use std::slice;
1111
use std::str;
1212
use std::vec;
1313

14-
use codespan_reporting::{Diagnostic, Label};
14+
use codespan_reporting::diagnostic::{Diagnostic, Label};
1515

16-
use crate::pos::{BytePos, Span, Spanned};
16+
use crate::{
17+
pos::{BytePos, Spanned},
18+
source::FileId,
19+
};
1720

1821
/// An error type which can represent multiple errors.
1922
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
@@ -155,7 +158,7 @@ impl<T: fmt::Display + fmt::Debug + Any> StdError for Errors<T> {
155158
/// Error type which contains information of which file and where in the file the error occurred
156159
#[derive(Clone, Debug)]
157160
pub struct InFile<E> {
158-
source: ::codespan::CodeMap,
161+
source: crate::source::CodeMap,
159162
error: Errors<Spanned<E, BytePos>>,
160163
}
161164

@@ -186,7 +189,7 @@ where
186189
impl<E: fmt::Display> InFile<E> {
187190
/// Creates a new `InFile` error which states that the error occurred in `file` using the file
188191
/// contents in `source` to provide a context to the span.
189-
pub fn new(source: ::codespan::CodeMap, error: Errors<Spanned<E, BytePos>>) -> InFile<E> {
192+
pub fn new(source: crate::source::CodeMap, error: Errors<Spanned<E, BytePos>>) -> InFile<E> {
190193
let err = InFile { source, error };
191194
// Verify that the source name can be accessed
192195
debug_assert!({
@@ -196,9 +199,9 @@ impl<E: fmt::Display> InFile<E> {
196199
err
197200
}
198201

199-
pub fn source_name(&self) -> &::codespan::FileName {
202+
pub fn source_name(&self) -> &str {
200203
self.source
201-
.find_file(self.error[0].span.start())
204+
.get(self.error[0].span.start())
202205
.unwrap_or_else(|| {
203206
panic!(
204207
"Source file does not exist in associated code map. Error: {}",
@@ -221,27 +224,34 @@ impl<E: fmt::Display> InFile<E> {
221224
E: AsDiagnostic,
222225
{
223226
let mut output = Vec::new();
224-
self.emit(
225-
&mut ::codespan_reporting::termcolor::NoColor::new(&mut output),
226-
)?;
227+
self.emit(&mut ::codespan_reporting::term::termcolor::NoColor::new(
228+
&mut output,
229+
))?;
227230
Ok(String::from_utf8(output).unwrap())
228231
}
229232

230-
pub fn emit<W>(&self, writer: &mut W) -> io::Result<()>
233+
pub fn emit(
234+
&self,
235+
writer: &mut dyn ::codespan_reporting::term::termcolor::WriteColor,
236+
) -> io::Result<()>
231237
where
232-
W: ?Sized + ::codespan_reporting::termcolor::WriteColor,
233238
E: AsDiagnostic,
234239
{
235240
let iter = self
236241
.error
237242
.iter()
238-
.map(AsDiagnostic::as_diagnostic)
243+
.map(|error| error.as_diagnostic(&self.source))
239244
.enumerate();
240245
for (i, diagnostic) in iter {
241246
if i != 0 {
242247
writeln!(writer)?;
243248
}
244-
::codespan_reporting::emit(&mut *writer, &self.source, &diagnostic)?;
249+
::codespan_reporting::term::emit(
250+
&mut *writer,
251+
&Default::default(),
252+
&self.source,
253+
&diagnostic,
254+
)?;
245255
}
246256
Ok(())
247257
}
@@ -251,10 +261,9 @@ impl<E: fmt::Display + AsDiagnostic> fmt::Display for InFile<E> {
251261
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
252262
let mut buffer = Vec::new();
253263
{
254-
let mut writer = ::codespan_reporting::termcolor::NoColor::new(&mut buffer);
264+
let mut writer = ::codespan_reporting::term::termcolor::NoColor::new(&mut buffer);
255265

256-
self.emit(&mut writer)
257-
.map_err(|_| fmt::Error)?;
266+
self.emit(&mut writer).map_err(|_| fmt::Error)?;
258267
}
259268

260269
write!(f, "{}", str::from_utf8(&buffer).unwrap())
@@ -295,16 +304,32 @@ impl<E, H> From<E> for Help<E, H> {
295304
}
296305

297306
pub trait AsDiagnostic {
298-
fn as_diagnostic(&self) -> Diagnostic;
307+
fn as_diagnostic(&self, map: &crate::source::CodeMap) -> Diagnostic<FileId>;
299308
}
300309

301310
impl<E> AsDiagnostic for Spanned<E, BytePos>
302311
where
303312
E: AsDiagnostic,
304313
{
305-
fn as_diagnostic(&self) -> Diagnostic {
306-
let mut diagnostic = self.value.as_diagnostic();
307-
diagnostic.labels.insert(0, Label::new_primary(self.span));
314+
fn as_diagnostic(&self, map: &crate::source::CodeMap) -> Diagnostic<FileId> {
315+
let mut diagnostic = self.value.as_diagnostic(map);
316+
for label in &mut diagnostic.labels {
317+
if label.file_id == FileId::default() {
318+
label.file_id = self.span.start();
319+
}
320+
if label.range == (0..0) {
321+
if let Some(range) = self.span.to_range(map) {
322+
label.range = range;
323+
}
324+
}
325+
}
326+
if diagnostic.labels.is_empty() {
327+
if let Some(range) = self.span.to_range(map) {
328+
diagnostic
329+
.labels
330+
.push(Label::primary(self.span.start(), range));
331+
}
332+
}
308333
diagnostic
309334
}
310335
}
@@ -314,20 +339,27 @@ where
314339
E: AsDiagnostic,
315340
H: fmt::Display,
316341
{
317-
fn as_diagnostic(&self) -> Diagnostic {
318-
let mut diagnostic = self.error.as_diagnostic();
342+
fn as_diagnostic(&self, map: &crate::source::CodeMap) -> Diagnostic<FileId> {
343+
let mut diagnostic = self.error.as_diagnostic(map);
319344
if let Some(ref help) = self.help {
320345
diagnostic.labels.push(
321-
Label::new_secondary(Span::new(BytePos::none(), BytePos::none()))
322-
.with_message(help.to_string()),
346+
Label::secondary(
347+
diagnostic
348+
.labels
349+
.last()
350+
.map(|label| label.file_id)
351+
.unwrap_or_default(),
352+
0..0,
353+
)
354+
.with_message(help.to_string()),
323355
);
324356
}
325357
diagnostic
326358
}
327359
}
328360

329361
impl AsDiagnostic for Box<dyn ::std::error::Error + Send + Sync> {
330-
fn as_diagnostic(&self) -> Diagnostic {
331-
Diagnostic::new_error(self.to_string())
362+
fn as_diagnostic(&self, _map: &crate::source::CodeMap) -> Diagnostic<FileId> {
363+
Diagnostic::error().with_message(self.to_string())
332364
}
333365
}

0 commit comments

Comments
 (0)