Skip to content

Commit c8197ea

Browse files
author
Jonathan Turner
committed
Working towards elision for simple single-annotation lines
1 parent 0677540 commit c8197ea

File tree

1 file changed

+45
-3
lines changed
  • src/libsyntax/errors/snippet

1 file changed

+45
-3
lines changed

src/libsyntax/errors/snippet/mod.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,51 @@ impl SnippetData {
175175
let mut output = vec![];
176176
for &(is_annotated, ref group) in line_groups.iter() {
177177
if is_annotated {
178-
let mut v: Vec<RenderedLine> =
179-
group.iter().flat_map(|line| self.render_line(line)).collect();
180-
output.append(&mut v);
178+
let mut annotation_ends_at_eol = false;
179+
let mut prev_ends_at_eol = false;
180+
let mut elide_unlabeled_region = false;
181+
182+
for group_line in group.iter() {
183+
let source_string =
184+
group_line.file.get_line(group_line.line_index).unwrap().to_string();
185+
186+
for annotation in &group_line.annotations {
187+
if annotation.end_col == source_string.len() {
188+
annotation_ends_at_eol = true;
189+
}
190+
}
191+
192+
let is_single_unlabeled_annotated_line =
193+
if group_line.annotations.len() == 1 {
194+
if let Some(annotation) = group_line.annotations.first() {
195+
match annotation.label {
196+
Some(_) => false,
197+
None => annotation.start_col == 0 &&
198+
annotation.end_col == source_string.len()
199+
}
200+
}
201+
else {
202+
false
203+
}
204+
}
205+
else {
206+
false
207+
};
208+
209+
if prev_ends_at_eol && is_single_unlabeled_annotated_line {
210+
if !elide_unlabeled_region {
211+
output.push(RenderedLine::from((String::from("..."), NoStyle, Elision)));
212+
elide_unlabeled_region = true;
213+
prev_ends_at_eol = true;
214+
}
215+
continue;
216+
}
217+
218+
let mut v = self.render_line(group_line);
219+
output.append(&mut v);
220+
221+
prev_ends_at_eol = annotation_ends_at_eol;
222+
}
181223
}
182224
else {
183225
if group.len() > 1 {

0 commit comments

Comments
 (0)