Skip to content

Commit 540e496

Browse files
authored
Merge pull request #325 from Muscraft/remove-attribute-code
chore: Remove specialized code for item attributes
2 parents 48dbf19 + b8d2cf5 commit 540e496

File tree

2 files changed

+3
-37
lines changed

2 files changed

+3
-37
lines changed

src/renderer/render.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,21 +1512,13 @@ fn emit_suggestion_default(
15121512
}
15131513
row_num += line_end.line - line_start.line;
15141514
}
1515-
let mut last_pos = 0;
1516-
let mut is_item_attribute = false;
15171515
let mut unhighlighted_lines = Vec::new();
15181516
for (line_pos, (line, highlight_parts)) in lines.by_ref().zip(highlights).enumerate() {
1519-
last_pos = line_pos;
1520-
15211517
// Remember lines that are not highlighted to hide them if needed
15221518
if highlight_parts.is_empty() && suggestion.fold {
15231519
unhighlighted_lines.push((line_pos, line));
15241520
continue;
15251521
}
1526-
if highlight_parts.len() == 1 && line.trim().starts_with("#[") && line.trim().ends_with(']')
1527-
{
1528-
is_item_attribute = true;
1529-
}
15301522

15311523
match unhighlighted_lines.len() {
15321524
0 => (),
@@ -1614,32 +1606,6 @@ fn emit_suggestion_default(
16141606
);
16151607
}
16161608

1617-
if matches!(show_code_change, DisplaySuggestion::Add) && is_item_attribute {
1618-
// The suggestion adds an entire line of code, ending on a newline, so we'll also
1619-
// print the *following* line, to provide context of what we're advising people to
1620-
// do. Otherwise you would only see contextless code that can be confused for
1621-
// already existing code, despite the colors and UI elements.
1622-
// We special case `#[derive(_)]\n` and other attribute suggestions, because those
1623-
// are the ones where context is most useful.
1624-
let file_lines = sm.span_to_lines(parts[0].span.end..parts[0].span.end);
1625-
let (lo, _) = sm.span_to_locations(parts[0].span.clone());
1626-
let line_num = lo.line;
1627-
if let Some(line) = sm.get_line(line_num) {
1628-
let line = normalize_whitespace(line);
1629-
draw_code_line(
1630-
renderer,
1631-
buffer,
1632-
&mut row_num,
1633-
&[],
1634-
line_num + last_pos + 1,
1635-
&line,
1636-
DisplaySuggestion::None,
1637-
max_line_num_len,
1638-
&file_lines,
1639-
is_multiline,
1640-
);
1641-
}
1642-
}
16431609
// This offset and the ones below need to be signed to account for replacement code
16441610
// that is shorter than the original code.
16451611
let mut offsets: Vec<(usize, isize)> = Vec::new();
@@ -1929,7 +1895,7 @@ fn draw_code_line(
19291895
[SubstitutionHighlight { start: 0, end }] if *end == line_to_add.len() => {
19301896
buffer.puts(*row_num, max_line_num_len + 1, "+ ", ElementStyle::Addition);
19311897
}
1932-
[] => {
1898+
[] | [SubstitutionHighlight { start: 0, end: 0 }] => {
19331899
// FIXME: needed? Doesn't get exercised in any test.
19341900
draw_col_separator_no_space(renderer, buffer, *row_num, max_line_num_len + 1);
19351901
}

tests/formatter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,7 +4869,7 @@ help: consider importing this module
48694869
|
48704870
1 |
48714871
2 + use std::cell;
4872-
3 ~ use st::cell::Cell;
4872+
3 | use st::cell::Cell;
48734873
4 |
48744874
5 | mod bar {
48754875
6 | pub fn bar() { bar::baz(); }
@@ -4900,7 +4900,7 @@ help: consider importing this module
49004900
╭╴
49014901
1 │
49024902
2 + use std::cell;
4903-
3 ± use st::cell::Cell;
4903+
3 use st::cell::Cell;
49044904
4 │
49054905
5 │ mod bar {
49064906
6 │ pub fn bar() { bar::baz(); }

0 commit comments

Comments
 (0)