Skip to content

Commit

Permalink
Remove extra vertical space for any label with no message set (#82)
Browse files Browse the repository at this point in the history
* remove empty lines for any label with no message in report

* change labels messages in new simple example
  • Loading branch information
Override-6 authored Jun 14, 2023
1 parent 889bc10 commit 1356421
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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

0 comments on commit 1356421

Please sign in to comment.