mirror of
https://gitee.com/openharmony/third_party_rust_codespan
synced 2024-11-23 07:20:23 +00:00
commit
1d7a556789
@ -127,7 +127,8 @@ pub fn emit<'files, F: Files<'files>>(
|
||||
let mut renderer = Renderer::new(writer, config);
|
||||
match config.display_style {
|
||||
DisplayStyle::Rich => RichDiagnostic::new(diagnostic, config).render(files, &mut renderer),
|
||||
DisplayStyle::Short => ShortDiagnostic::new(diagnostic).render(files, &mut renderer),
|
||||
DisplayStyle::Medium => ShortDiagnostic::new(diagnostic, true).render(files, &mut renderer),
|
||||
DisplayStyle::Short => ShortDiagnostic::new(diagnostic, false).render(files, &mut renderer),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,16 @@ pub enum DisplayStyle {
|
||||
///
|
||||
/// ```
|
||||
Rich,
|
||||
/// Output a condensed diagnostic, with a line number, severity, message and notes (if any).
|
||||
///
|
||||
/// ```text
|
||||
/// test:2:9: error[E0001]: unexpected type in `+` application
|
||||
/// = expected type `Int`
|
||||
/// found type `String`
|
||||
///
|
||||
/// error[E0002]: Bad config found
|
||||
/// ```
|
||||
Medium,
|
||||
/// Output a short diagnostic, with a line number, severity, and message.
|
||||
///
|
||||
/// ```text
|
||||
|
@ -455,6 +455,7 @@ where
|
||||
/// Output a short diagnostic, with a line number, severity, and message.
|
||||
pub struct ShortDiagnostic<'diagnostic, FileId> {
|
||||
diagnostic: &'diagnostic Diagnostic<FileId>,
|
||||
show_notes: bool,
|
||||
}
|
||||
|
||||
impl<'diagnostic, FileId> ShortDiagnostic<'diagnostic, FileId>
|
||||
@ -463,8 +464,12 @@ where
|
||||
{
|
||||
pub fn new(
|
||||
diagnostic: &'diagnostic Diagnostic<FileId>,
|
||||
show_notes: bool,
|
||||
) -> ShortDiagnostic<'diagnostic, FileId> {
|
||||
ShortDiagnostic { diagnostic }
|
||||
ShortDiagnostic {
|
||||
diagnostic,
|
||||
show_notes,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render<'files>(
|
||||
@ -515,6 +520,18 @@ where
|
||||
)?;
|
||||
}
|
||||
|
||||
if self.show_notes {
|
||||
// Additional notes
|
||||
//
|
||||
// ```text
|
||||
// = expected type `Int`
|
||||
// found type `String`
|
||||
// ```
|
||||
for note in &self.diagnostic.notes {
|
||||
renderer.render_snippet_note(0, note)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
{fg:Red bold bright}bug{bold bright}: {/}
|
||||
{fg:Red bold bright}error{bold bright}: {/}
|
||||
{fg:Yellow bold bright}warning{bold bright}: {/}
|
||||
{fg:Green bold bright}note{bold bright}: {/}
|
||||
{fg:Cyan bold bright}help{bold bright}: {/}
|
||||
{fg:Red bold bright}bug{bold bright}: {/}
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
bug:
|
||||
error:
|
||||
warning:
|
||||
note:
|
||||
help:
|
||||
bug:
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
hello:1:7: {fg:Green bold bright}note{bold bright}: middle{/}
|
||||
hello:1:13: {fg:Green bold bright}note{bold bright}: end of line{/}
|
||||
hello:2:11: {fg:Green bold bright}note{bold bright}: end of line{/}
|
||||
hello:3:4: {fg:Green bold bright}note{bold bright}: end of file{/}
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
hello:1:7: note: middle
|
||||
hello:1:13: note: end of line
|
||||
hello:2:11: note: end of line
|
||||
hello:3:4: note: end of file
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
FizzBuzz.fun:8:12: {fg:Red bold bright}error[E0308]{bold bright}: `case` clauses have incompatible types{/}
|
||||
{fg:Blue}={/} expected type `String`
|
||||
found type `Nat`
|
||||
FizzBuzz.fun:16:16: {fg:Red bold bright}error[E0308]{bold bright}: `case` clauses have incompatible types{/}
|
||||
{fg:Blue}={/} expected type `String`
|
||||
found type `Nat`
|
||||
|
@ -0,0 +1,11 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
FizzBuzz.fun:8:12: error[E0308]: `case` clauses have incompatible types
|
||||
= expected type `String`
|
||||
found type `Nat`
|
||||
FizzBuzz.fun:16:16: error[E0308]: `case` clauses have incompatible types
|
||||
= expected type `String`
|
||||
found type `Nat`
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
{fg:Red bold bright}error{bold bright}: a message{/}
|
||||
{fg:Yellow bold bright}warning{bold bright}: a message{/}
|
||||
{fg:Green bold bright}note{bold bright}: a message{/}
|
||||
{fg:Cyan bold bright}help{bold bright}: a message{/}
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
error: a message
|
||||
warning: a message
|
||||
note: a message
|
||||
help: a message
|
||||
|
@ -0,0 +1,13 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
{fg:Red bold bright}error{bold bright}: a message{/}
|
||||
{fg:Blue}={/} a note
|
||||
{fg:Yellow bold bright}warning{bold bright}: a message{/}
|
||||
{fg:Blue}={/} a note
|
||||
{fg:Green bold bright}note{bold bright}: a message{/}
|
||||
{fg:Blue}={/} a note
|
||||
{fg:Cyan bold bright}help{bold bright}: a message{/}
|
||||
{fg:Blue}={/} a note
|
||||
|
@ -0,0 +1,13 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
error: a message
|
||||
= a note
|
||||
warning: a message
|
||||
= a note
|
||||
note: a message
|
||||
= a note
|
||||
help: a message
|
||||
= a note
|
||||
|
@ -0,0 +1,12 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
Data/Nat.fun:7:13: {fg:Red bold bright}error{bold bright}: unknown builtin: `NATRAL`{/}
|
||||
{fg:Blue}={/} there is a builtin with a similar name: `NATURAL`
|
||||
Data/Nat.fun:17:16: {fg:Yellow bold bright}warning{bold bright}: unused parameter pattern: `n₂`{/}
|
||||
{fg:Blue}={/} consider using a wildcard pattern: `_`
|
||||
Test.fun:4:11: {fg:Red bold bright}error[E0001]{bold bright}: unexpected type in application of `_+_`{/}
|
||||
{fg:Blue}={/} expected type `Nat`
|
||||
found type `String`
|
||||
|
@ -0,0 +1,12 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
Data/Nat.fun:7:13: error: unknown builtin: `NATRAL`
|
||||
= there is a builtin with a similar name: `NATURAL`
|
||||
Data/Nat.fun:17:16: warning: unused parameter pattern: `n₂`
|
||||
= consider using a wildcard pattern: `_`
|
||||
Test.fun:4:11: error[E0001]: unexpected type in application of `_+_`
|
||||
= expected type `Nat`
|
||||
found type `String`
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
codespan/src/file.rs:4:34: {fg:Red bold bright}error[E0308]{bold bright}: match arms have incompatible types{/}
|
||||
{fg:Blue}={/} expected type `Result<ByteIndex, LineIndexOutOfBoundsError>`
|
||||
found type `LineIndexOutOfBoundsError`
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
codespan/src/file.rs:4:34: error[E0308]: match arms have incompatible types
|
||||
= expected type `Result<ByteIndex, LineIndexOutOfBoundsError>`
|
||||
found type `LineIndexOutOfBoundsError`
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
nested_impl_trait.rs:5:56: {fg:Red bold bright}error[E0666]{bold bright}: nested `impl Trait` is not allowed{/}
|
||||
typeck_type_placeholder_item.rs:1:18: {fg:Red bold bright}error[E0121]{bold bright}: the type placeholder `_` is not allowed within types on item signatures{/}
|
||||
typeck_type_placeholder_item.rs:2:25: {fg:Red bold bright}error[E0121]{bold bright}: the type placeholder `_` is not allowed within types on item signatures{/}
|
||||
typeck_type_placeholder_item.rs:2:28: {fg:Red bold bright}error[E0121]{bold bright}: the type placeholder `_` is not allowed within types on item signatures{/}
|
||||
no_send_res_ports.rs:25:5: {fg:Red bold bright}error[E0277]{bold bright}: `std::rc::Rc<()>` cannot be sent between threads safely{/}
|
||||
{fg:Blue}={/} help: within `[closure@no_send_res_ports.rs:29:19: 33:6 x:main::Foo]`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<()>`
|
||||
{fg:Blue}={/} note: required because it appears within the type `Port<()>`
|
||||
{fg:Blue}={/} note: required because it appears within the type `main::Foo`
|
||||
{fg:Blue}={/} note: required because it appears within the type `[closure@no_send_res_ports.rs:29:19: 33:6 x:main::Foo]`
|
||||
{fg:Red bold bright}error{bold bright}: aborting due 5 previous errors{/}
|
||||
{fg:Blue}={/} Some errors have detailed explanations: E0121, E0277, E0666.
|
||||
{fg:Blue}={/} For more information about an error, try `rustc --explain E0121`.
|
||||
|
@ -0,0 +1,17 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
nested_impl_trait.rs:5:56: error[E0666]: nested `impl Trait` is not allowed
|
||||
typeck_type_placeholder_item.rs:1:18: error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
typeck_type_placeholder_item.rs:2:25: error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
typeck_type_placeholder_item.rs:2:28: error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
no_send_res_ports.rs:25:5: error[E0277]: `std::rc::Rc<()>` cannot be sent between threads safely
|
||||
= help: within `[closure@no_send_res_ports.rs:29:19: 33:6 x:main::Foo]`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<()>`
|
||||
= note: required because it appears within the type `Port<()>`
|
||||
= note: required because it appears within the type `main::Foo`
|
||||
= note: required because it appears within the type `[closure@no_send_res_ports.rs:29:19: 33:6 x:main::Foo]`
|
||||
error: aborting due 5 previous errors
|
||||
= Some errors have detailed explanations: E0121, E0277, E0666.
|
||||
= For more information about an error, try `rustc --explain E0121`.
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
tests/main.js:4:3: warning[ParserWarning]: The strict mode declaration in the body of function `foo` is redundant, as the outer scope is already in strict mode
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
one_line.rs:3:12: {fg:Red bold bright}error[E0499]{bold bright}: cannot borrow `v` as mutable more than once at a time{/}
|
||||
{fg:Red bold bright}error{bold bright}: aborting due to previous error{/}
|
||||
{fg:Blue}={/} For more information about this error, try `rustc --explain E0499`.
|
||||
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
one_line.rs:3:12: error[E0499]: cannot borrow `v` as mutable more than once at a time
|
||||
error: aborting due to previous error
|
||||
= For more information about this error, try `rustc --explain E0499`.
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_color(&config)
|
||||
---
|
||||
same_range:1:5: {fg:Red bold bright}error{bold bright}: Unexpected token{/}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
same_range:1:5: error: Unexpected token
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
unicode.rs:1:8: error[E0703]: invalid ABI: found `路濫狼á́́`
|
||||
= valid ABIs:
|
||||
- aapcs
|
||||
- amdgpu-kernel
|
||||
- C
|
||||
- cdecl
|
||||
- efiapi
|
||||
- fastcall
|
||||
- msp430-interrupt
|
||||
- platform-intrinsic
|
||||
- ptx-kernel
|
||||
- Rust
|
||||
- rust-call
|
||||
- rust-intrinsic
|
||||
- stdcall
|
||||
- system
|
||||
- sysv64
|
||||
- thiscall
|
||||
- unadjusted
|
||||
- vectorcall
|
||||
- win64
|
||||
- x86-interrupt
|
||||
error: aborting due to previous error
|
||||
= For more information about this error, try `rustc --explain E0703`.
|
||||
|
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: codespan-reporting/tests/term.rs
|
||||
expression: TEST_DATA.emit_no_color(&config)
|
||||
---
|
||||
moon_jump.rs:1:1: error[E01]: cow may not jump during new moon.
|
||||
note: invalid unicode range
|
||||
note: invalid unicode range
|
||||
note: invalid unicode range
|
||||
|
@ -26,6 +26,17 @@ macro_rules! test_emit {
|
||||
insta::assert_snapshot!(TEST_DATA.emit_color(&config));
|
||||
}
|
||||
};
|
||||
(medium_color) => {
|
||||
#[test]
|
||||
fn medium_color() {
|
||||
let config = Config {
|
||||
display_style: DisplayStyle::Medium,
|
||||
..TEST_CONFIG.clone()
|
||||
};
|
||||
|
||||
insta::assert_snapshot!(TEST_DATA.emit_color(&config));
|
||||
}
|
||||
};
|
||||
(short_color) => {
|
||||
#[test]
|
||||
fn short_color() {
|
||||
@ -48,6 +59,17 @@ macro_rules! test_emit {
|
||||
insta::assert_snapshot!(TEST_DATA.emit_no_color(&config));
|
||||
}
|
||||
};
|
||||
(medium_no_color) => {
|
||||
#[test]
|
||||
fn medium_no_color() {
|
||||
let config = Config {
|
||||
display_style: DisplayStyle::Medium,
|
||||
..TEST_CONFIG.clone()
|
||||
};
|
||||
|
||||
insta::assert_snapshot!(TEST_DATA.emit_no_color(&config));
|
||||
}
|
||||
};
|
||||
(short_no_color) => {
|
||||
#[test]
|
||||
fn short_no_color() {
|
||||
@ -82,8 +104,10 @@ mod empty {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -130,8 +154,10 @@ mod same_line {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -272,8 +298,10 @@ mod overlapping {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -296,8 +324,10 @@ mod message {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -320,8 +350,10 @@ mod message_and_notes {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -379,8 +411,10 @@ mod empty_ranges {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -405,8 +439,10 @@ mod same_ranges {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -489,8 +525,10 @@ mod multifile {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -566,8 +604,10 @@ mod fizz_buzz {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -614,8 +654,10 @@ mod multiline_overlapping {
|
||||
}
|
||||
|
||||
test_emit!(rich_color);
|
||||
test_emit!(medium_color);
|
||||
test_emit!(short_color);
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -819,6 +861,7 @@ mod unicode {
|
||||
}
|
||||
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -869,6 +912,7 @@ mod unicode_spans {
|
||||
}
|
||||
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
@ -904,6 +948,7 @@ mod position_indicator {
|
||||
}
|
||||
|
||||
test_emit!(rich_no_color);
|
||||
test_emit!(medium_no_color);
|
||||
test_emit!(short_no_color);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user