Skip to content

Commit b3b2032

Browse files
committed
Fix too many anonymized line numbers
This expands the logic for replacing line numbers with `LL` so that line numbers are only replaced, when they are actually provided. When `lineno` is `None`, no `LL` should be shown in the output.
1 parent e23e557 commit b3b2032

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/formatter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl DisplayListFormatter {
303303
inline_marks,
304304
line,
305305
} => {
306-
let lineno = if self.anonymized_line_numbers {
306+
let lineno = if self.anonymized_line_numbers && lineno.is_some() {
307307
Self::ANONYMIZED_LINE_NUM.to_string()
308308
} else {
309309
self.format_lineno(*lineno, lineno_width)

tests/formatter.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,26 @@ fn test_anon_lines() {
515515
range: (0, 19),
516516
},
517517
},
518+
DisplayLine::Source {
519+
lineno: None,
520+
inline_marks: vec![],
521+
line: DisplaySourceLine::Empty,
522+
},
523+
DisplayLine::Source {
524+
lineno: None,
525+
inline_marks: vec![],
526+
line: DisplaySourceLine::Content {
527+
text: "abc".to_string(),
528+
range: (0, 19),
529+
},
530+
},
518531
]);
519532

520533
let dlf = DisplayListFormatter::new(false, true);
521534

522535
assert_eq!(
523536
dlf.format(&dl),
524-
"LL | This is an example\nLL | of content lines"
537+
"LL | This is an example\nLL | of content lines\n |\n | abc"
525538
);
526539
}
527540

0 commit comments

Comments
 (0)