Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra vertical space for any label with no message set #82

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ariadne::{Report, ReportKind, Label, Source};
use yansi::Color;
use ariadne::{Report, ReportKind, Label, Source, Config};

fn main() {
Report::build(ReportKind::Error, (), 34)
Expand All @@ -8,4 +9,17 @@ fn main() {
.finish()
.print(Source::from(include_str!("sample.tao")))
.unwrap();

const SOURCE: &str = "a b c d e f";
// also supports labels with no messages to only emphasis on some areas
Report::build(ReportKind::Error, (), 34)
.with_message("Incompatible types")
.with_config(Config::default().with_compact(true))
.with_label(Label::new(0..1).with_color(Color::Red))
.with_label(Label::new(2..3).with_color(Color::Blue).with_message("`b` for banana").with_order(1))
.with_label(Label::new(4..5).with_color(Color::Green))
.with_label(Label::new(7..9).with_color(Color::Cyan).with_message("`e` for emerald"))
.finish()
.print(Source::from(SOURCE))
.unwrap();
}
5 changes: 4 additions & 1 deletion src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ impl<S: Span> Report<'_, S> {
// Arrows
for row in 0..line_labels.len() {
let line_label = &line_labels[row];

//No message to draw thus no arrow to draw
if line_label.label.msg.is_none() {
continue
}
if !self.config.compact {
// Margin alternate
write_margin(
Expand Down