I'm using Rocket (which is awesome, BTW) and noticed that sometimes error messages in my editor would be mangled with ASCII color codes, making the error messages very hard to read.
In terminal:

In editor:

I thought this was an issue with rust-analyzer, since I do not see the ASCII color codes printed if I pipe cargo build into cat, so I posted an issue there. But the people over there say that it is caused by your implementation of Display here:
|
impl fmt::Display for Line<'_> { |
|
#[cfg(all(feature = "colors", not(nightly_diagnostics)))] |
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
|
use yansi::{Paint, Color}; |
|
let style = match self.level { |
|
Level::Error => Color::Red.bold(), |
|
Level::Warning => Color::Yellow.bold(), |
|
Level::Note => Color::Green.bold(), |
|
Level::Help => Color::Cyan.bold(), |
|
}; |
|
|
|
let ((prefix, suffix), msg) = (self.kind.split(), self.msg.primary()); |
|
write!(f, "{}{}{}{}", prefix, self.level.paint(style), suffix, msg.bold()) |
|
} |
|
|
|
#[cfg(not(all(feature = "colors", not(nightly_diagnostics))))] |
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
|
let (prefix, suffix) = self.kind.split(); |
|
write!(f, "{}{}{}{}", prefix, self.level, suffix, self.msg) |
|
} |
|
} |
You should really read rust-lang/rust-analyzer#15443 first to get all of the context.
I have not yet wrapped my head around all the parts involved here, since I am pretty new to Rust. But I thought I'd post this here to see what you think.
Steps to reproduce
- Create the following crate:
cargo new -q foo
cd foo
cargo add -q rocket@0.5.0-rc.3
cat <<EOF > src/main.rs
use rocket::UriDisplayPath;
fn main() {
println!("Hello, world!");
}
#[derive(UriDisplayPath)]
pub enum Foo {
Bar,
}
EOF
- Optionally run
cargo check.
- Open
src/main.rs with Vim.
I'm using Rocket (which is awesome, BTW) and noticed that sometimes error messages in my editor would be mangled with ASCII color codes, making the error messages very hard to read.
In terminal:
In editor:
I thought this was an issue with rust-analyzer, since I do not see the ASCII color codes printed if I pipe
cargo buildintocat, so I posted an issue there. But the people over there say that it is caused by your implementation of Display here:proc-macro2-diagnostics/src/line.rs
Lines 77 to 97 in 45fa2d6
You should really read rust-lang/rust-analyzer#15443 first to get all of the context.
I have not yet wrapped my head around all the parts involved here, since I am pretty new to Rust. But I thought I'd post this here to see what you think.
Steps to reproduce
cargo check.src/main.rswith Vim.