mirror of
https://gitee.com/openharmony/third_party_rust_codespan
synced 2024-11-27 01:21:31 +00:00
Colour source code within primary label ranges
This commit is contained in:
parent
0eb19865cf
commit
753607ea5e
@ -55,17 +55,17 @@
|
||||
<span class="fg blue">┌─</span> FizzBuzz.fun:10:15
|
||||
<span class="fg blue">│</span>
|
||||
<span class="fg blue">10</span> <span class="fg blue">│</span> fizz₂ : Nat → String
|
||||
<span class="fg blue">│</span> <span class="fg blue">------ expected type `String` found here</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">------</span> <span class="fg blue">expected type `String` found here</span>
|
||||
<span class="fg blue">11</span> <span class="fg blue">│</span> fizz₂ num =
|
||||
<span class="fg blue">12</span> <span class="fg blue">│</span> <span class="fg blue">╭</span> case (mod num 5) (mod num 3) of
|
||||
<span class="fg blue">13</span> <span class="fg blue">│</span> <span class="fg blue">│</span> 0 0 => "FizzBuzz"
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">---------- this is found to be of type `String`</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">----------</span> <span class="fg blue">this is found to be of type `String`</span>
|
||||
<span class="fg blue">14</span> <span class="fg blue">│</span> <span class="fg blue">│</span> 0 _ => "Fizz"
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">------ this is found to be of type `String`</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">------</span> <span class="fg blue">this is found to be of type `String`</span>
|
||||
<span class="fg blue">15</span> <span class="fg blue">│</span> <span class="fg blue">│</span> _ 0 => "Buzz"
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">------ this is found to be of type `String`</span>
|
||||
<span class="fg blue">16</span> <span class="fg blue">│</span> <span class="fg blue">│</span> _ _ => num
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg red">^^^ expected `String`, found `Nat`</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg blue">------</span> <span class="fg blue">this is found to be of type `String`</span>
|
||||
<span class="fg blue">16</span> <span class="fg blue">│</span> <span class="fg blue">│</span> _ _ => <span class="fg red">num</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">│</span> <span class="fg red">^^^</span> <span class="fg red">expected `String`, found `Nat`</span>
|
||||
<span class="fg blue">│</span> <span class="fg blue">╰</span><span class="fg blue">──────────────────' `case` clauses have incompatible types</span>
|
||||
<span class="fg blue">│</span>
|
||||
<span class="fg blue">=</span> expected type `String`
|
||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.3 KiB |
@ -266,12 +266,44 @@ impl<'writer, 'config> Renderer<'writer, 'config> {
|
||||
|
||||
// Write source text
|
||||
write!(self, " ")?;
|
||||
let mut in_primary = false;
|
||||
for (metrics, ch) in self.char_metrics(source.char_indices()) {
|
||||
let column_range = metrics.byte_index..(metrics.byte_index + ch.len_utf8());
|
||||
|
||||
// Check if we are overlapping a primary label
|
||||
let is_primary = single_labels.iter().any(|(ls, range, _)| {
|
||||
*ls == LabelStyle::Primary && is_overlapping(range, &column_range)
|
||||
}) || multi_labels.iter().any(|(_, label)| match label {
|
||||
MultiLabel::Top(ls, range) => {
|
||||
*ls == LabelStyle::Primary && column_range.start >= range.end
|
||||
}
|
||||
MultiLabel::TopLeft(ls) | MultiLabel::Left(ls) => *ls == LabelStyle::Primary,
|
||||
MultiLabel::Bottom(ls, range, _) => {
|
||||
*ls == LabelStyle::Primary && column_range.end <= range.end
|
||||
}
|
||||
});
|
||||
|
||||
// Set the source color if we are in a primary label
|
||||
match (is_primary, in_primary) {
|
||||
(true, true) | (false, false) => {}
|
||||
(true, false) => {
|
||||
self.set_color(self.styles().label(severity, LabelStyle::Primary))?;
|
||||
in_primary = true;
|
||||
}
|
||||
(false, true) => {
|
||||
self.reset()?;
|
||||
in_primary = false;
|
||||
}
|
||||
}
|
||||
|
||||
match ch {
|
||||
'\t' => (0..metrics.unicode_width).try_for_each(|_| write!(self, " "))?,
|
||||
_ => write!(self, "{}", ch)?,
|
||||
}
|
||||
}
|
||||
if in_primary {
|
||||
self.reset()?;
|
||||
}
|
||||
write!(self, "\n")?;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Green bold bright}note{bold bright}: middle{/}
|
||||
{fg:Blue}┌─{/} hello:1:7
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} Hello world!
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} Hello {fg:Green}w{/}orld!
|
||||
{fg:Blue}│{/} {fg:Green}^{/} {fg:Green}middle{/}
|
||||
|
||||
{fg:Green bold bright}note{bold bright}: end of line{/}
|
||||
|
@ -12,7 +12,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Blue}5{/} {fg:Blue}│{/} {fg:Blue}│{/} 0 0 => "FizzBuzz"
|
||||
{fg:Blue}6{/} {fg:Blue}│{/} {fg:Blue}│{/} 0 _ => "Fizz"
|
||||
{fg:Blue}7{/} {fg:Blue}│{/} {fg:Blue}│{/} _ 0 => "Buzz"
|
||||
{fg:Blue}8{/} {fg:Blue}│{/} {fg:Blue}│{/} _ _ => num
|
||||
{fg:Blue}8{/} {fg:Blue}│{/} {fg:Blue}│{/} _ _ => {fg:Red}num{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Red}^^^{/} {fg:Red}expected `String`, found `Nat`{/}
|
||||
{fg:Blue}│{/} {fg:Blue}╰{/}{fg:Blue}──────────────' `case` clauses have incompatible types{/}
|
||||
{fg:Blue}│{/}
|
||||
@ -32,7 +32,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}------{/} {fg:Blue}this is found to be of type `String`{/}
|
||||
{fg:Blue}15{/} {fg:Blue}│{/} {fg:Blue}│{/} _ 0 => "Buzz"
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}------{/} {fg:Blue}this is found to be of type `String`{/}
|
||||
{fg:Blue}16{/} {fg:Blue}│{/} {fg:Blue}│{/} _ _ => num
|
||||
{fg:Blue}16{/} {fg:Blue}│{/} {fg:Blue}│{/} _ _ => {fg:Red}num{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Red}^^^{/} {fg:Red}expected `String`, found `Nat`{/}
|
||||
{fg:Blue}│{/} {fg:Blue}╰{/}{fg:Blue}──────────────────' `case` clauses have incompatible types{/}
|
||||
{fg:Blue}│{/}
|
||||
|
@ -5,7 +5,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error{bold bright}: unknown builtin: `NATRAL`{/}
|
||||
{fg:Blue}┌─{/} Data/Nat.fun:7:13
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}7{/} {fg:Blue}│{/} {-# BUILTIN NATRAL Nat #-}
|
||||
{fg:Blue}7{/} {fg:Blue}│{/} {-# BUILTIN {fg:Red}NATRAL{/} Nat #-}
|
||||
{fg:Blue}│{/} {fg:Red}^^^^^^{/} {fg:Red}unknown builtin{/}
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}={/} there is a builtin with a similar name: `NATURAL`
|
||||
@ -13,7 +13,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Yellow bold bright}warning{bold bright}: unused parameter pattern: `n₂`{/}
|
||||
{fg:Blue}┌─{/} Data/Nat.fun:17:16
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}17{/} {fg:Blue}│{/} zero - succ n₂ = zero
|
||||
{fg:Blue}17{/} {fg:Blue}│{/} zero - succ {fg:Yellow}n₂{/} = zero
|
||||
{fg:Blue}│{/} {fg:Yellow}^^{/} {fg:Yellow}unused parameter{/}
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}={/} consider using a wildcard pattern: `_`
|
||||
@ -21,7 +21,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0001]{bold bright}: unexpected type in application of `_+_`{/}
|
||||
{fg:Blue}┌─{/} Test.fun:4:11
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue} 4{/} {fg:Blue}│{/} _ = 123 + "hello"
|
||||
{fg:Blue} 4{/} {fg:Blue}│{/} _ = 123 + {fg:Red}"hello"{/}
|
||||
{fg:Blue}│{/} {fg:Red}^^^^^^^{/} {fg:Red}expected `Nat`, found `String`{/}
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}┌─{/} Data/Nat.fun:11:1
|
||||
|
@ -10,11 +10,11 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}---------------------------------------------{/} {fg:Blue}this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`{/}
|
||||
{fg:Blue}3{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Equal => Ok(self.source_span().end()),
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}----------------------------{/} {fg:Blue}this is found to be of type `Result<ByteIndex, LineIndexOutOfBoundsError>`{/}
|
||||
{fg:Blue}4{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Greater => LineIndexOutOfBoundsError {
|
||||
{fg:Blue}4{/} {fg:Blue}│{/} {fg:Blue}│{/} Ordering::Greater => {fg:Red}LineIndexOutOfBoundsError {{/}
|
||||
{fg:Blue}│{/} {fg:Red}╭{/}{fg:Red}─{/}{fg:Blue}│{/}{fg:Red}──────────────────────────────────^{/}
|
||||
{fg:Blue}5{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} given: line_index,
|
||||
{fg:Blue}6{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} max: self.last_line_index(),
|
||||
{fg:Blue}7{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} },
|
||||
{fg:Blue}5{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} {fg:Red} given: line_index,{/}
|
||||
{fg:Blue}6{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} {fg:Red} max: self.last_line_index(),{/}
|
||||
{fg:Blue}7{/} {fg:Blue}│{/} {fg:Red}│{/} {fg:Blue}│{/} {fg:Red} }{/},
|
||||
{fg:Blue}│{/} {fg:Red}╰{/}{fg:Red}─{/}{fg:Blue}│{/}{fg:Red}─────────────^ expected enum `Result`, found struct `LineIndexOutOfBoundsError`{/}
|
||||
{fg:Blue}8{/} {fg:Blue}│{/} {fg:Blue}│{/} }
|
||||
{fg:Blue}│{/} {fg:Blue}╰{/}{fg:Blue}─────────' `match` arms have incompatible types{/}
|
||||
|
@ -5,7 +5,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0666]{bold bright}: nested `impl Trait` is not allowed{/}
|
||||
{fg:Blue}┌─{/} nested_impl_trait.rs:5:46
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}5{/} {fg:Blue}│{/} fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
|
||||
{fg:Blue}5{/} {fg:Blue}│{/} fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<{fg:Red}impl Debug{/}> { x }
|
||||
{fg:Blue}│{/} {fg:Blue}----------{fg:Red}^^^^^^^^^^{fg:Blue}-{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Red}│{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Red}nested `impl Trait` here{/}
|
||||
@ -14,7 +14,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0121]{bold bright}: the type placeholder `_` is not allowed within types on item signatures{/}
|
||||
{fg:Blue}┌─{/} typeck_type_placeholder_item.rs:1:18
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} fn fn_test1() -> _ { 5 }
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} fn fn_test1() -> {fg:Red}_{/} { 5 }
|
||||
{fg:Blue}│{/} {fg:Red}^{/}
|
||||
{fg:Blue}│{/} {fg:Red}│{/}
|
||||
{fg:Blue}│{/} {fg:Red}not allowed in type signatures{/}
|
||||
@ -23,7 +23,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0121]{bold bright}: the type placeholder `_` is not allowed within types on item signatures{/}
|
||||
{fg:Blue}┌─{/} typeck_type_placeholder_item.rs:2:24
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}2{/} {fg:Blue}│{/} fn fn_test2(x: i32) -> (_, _) { (x, x) }
|
||||
{fg:Blue}2{/} {fg:Blue}│{/} fn fn_test2(x: i32) -> ({fg:Red}_{/}, {fg:Red}_{/}) { (x, x) }
|
||||
{fg:Blue}│{/} {fg:Blue}-{fg:Red}^{fg:Blue}--{fg:Red}^{fg:Blue}-{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/}{fg:Red}│{/} {fg:Red}│{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/}{fg:Red}│{/} {fg:Red}not allowed in type signatures{/}
|
||||
@ -33,7 +33,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0277]{bold bright}: `std::rc::Rc<()>` cannot be sent between threads safely{/}
|
||||
{fg:Blue}┌─{/} no_send_res_ports.rs:25:5
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}25{/} {fg:Blue}│{/} thread::spawn(move|| {
|
||||
{fg:Blue}25{/} {fg:Blue}│{/} {fg:Red}thread::spawn{/}(move|| {
|
||||
{fg:Blue}│{/} {fg:Red}^^^^^^^^^^^^^{/} {fg:Red}`std::rc::Rc<()>` cannot be sent between threads safely{/}
|
||||
{fg:Blue}│{/} {fg:Blue}╭{/}{fg:Blue}───────────────────'{/}
|
||||
{fg:Blue}26{/} {fg:Blue}│{/} {fg:Blue}│{/} let y = x;
|
||||
|
@ -5,7 +5,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error[E0499]{bold bright}: cannot borrow `v` as mutable more than once at a time{/}
|
||||
{fg:Blue}┌─{/} one_line.rs:3:5
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}3{/} {fg:Blue}│{/} v.push(v.pop().unwrap());
|
||||
{fg:Blue}3{/} {fg:Blue}│{/} v.push({fg:Red}v{/}.pop().unwrap());
|
||||
{fg:Blue}│{/} {fg:Blue}-{/} {fg:Blue}----{/} {fg:Red}^{/} {fg:Red}second mutable borrow occurs here{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}│{/}
|
||||
{fg:Blue}│{/} {fg:Blue}│{/} {fg:Blue}first mutable borrow occurs here{/}
|
||||
|
@ -5,7 +5,7 @@ expression: TEST_DATA.emit_color(&config)
|
||||
{fg:Red bold bright}error{bold bright}: Unexpected token{/}
|
||||
{fg:Blue}┌─{/} same_range:1:5
|
||||
{fg:Blue}│{/}
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} ::S { }
|
||||
{fg:Blue}1{/} {fg:Blue}│{/} ::S {fg:Red}{{/} }
|
||||
{fg:Blue}│{/} {fg:Red}^{/}
|
||||
{fg:Blue}│{/} {fg:Red}│{/}
|
||||
{fg:Blue}│{/} {fg:Red}Unexpected '{'{/}
|
||||
|
Loading…
Reference in New Issue
Block a user