Skip to content

Commit 1f5309c

Browse files
committed
return earlier for file-level snippets
1 parent d000254 commit 1f5309c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

crates/ruff_annotate_snippets/src/renderer/display_list.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,17 @@ fn format_snippet<'m>(
11651165
let main_range = snippet.annotations.first().map(|x| x.range.start);
11661166
let origin = snippet.origin;
11671167
let need_empty_header = origin.is_some() || is_first;
1168+
11681169
let is_file_level = snippet.annotations.iter().any(|ann| ann.is_file_level);
1170+
if is_file_level {
1171+
let header = format_header(origin, main_range, &[], is_first);
1172+
return DisplaySet {
1173+
display_lines: header.map_or_else(Vec::new, |header| vec![header]),
1174+
margin: Margin::new(0, 0, 0, 0, term_width, 0),
1175+
hide_severity,
1176+
};
1177+
}
1178+
11691179
let mut body = format_body(
11701180
snippet,
11711181
need_empty_header,
@@ -1181,14 +1191,6 @@ fn format_snippet<'m>(
11811191
body.display_lines.insert(0, header);
11821192
}
11831193

1184-
// TODO(brent) This does exactly what we want (only printing the header and not an empty
1185-
// annotation for file-level diagnostics), but it would obviously be nicer not to format them at
1186-
// all instead of truncating at the end. It's just not quite clear to me which parts of
1187-
// `format_body` are essential, especially mutating the `Margin` components.
1188-
if is_file_level {
1189-
body.display_lines.truncate(1);
1190-
}
1191-
11921194
body
11931195
}
11941196

0 commit comments

Comments
 (0)