Skip to content

Commit ae9f49b

Browse files
bartlomiejuclaude
andcommitted
fix: resolve clippy warnings and remove context lines between hunks
Remove context lines between diff hunks that were causing spec test failures. Remove unused prev_after_end variable and dead code (write_context_line, fmt_rem_text, fmt_add_text). Update test expectations since imara-diff correctly identifies unchanged lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 057583a commit ae9f49b

File tree

1 file changed

+3
-58
lines changed

1 file changed

+3
-58
lines changed

libs/resolver/display.rs

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,12 @@ impl<'a> DiffBuilder<'a> {
6060

6161
fn handle_diff(mut self, diff: Diff) -> String {
6262
let mut prev_before_end: u32 = 0;
63-
let mut prev_after_end: u32 = 0;
6463

6564
for hunk in diff.hunks() {
66-
// Show unchanged context lines between hunks
65+
// Skip unchanged lines between hunks
6766
let gap_len = (hunk.before.start - prev_before_end) as usize;
68-
if gap_len > 0 {
69-
if prev_before_end == 0 {
70-
// Before the first hunk — just skip, no context needed
71-
self.orig_line += gap_len;
72-
self.edit_line += gap_len;
73-
} else {
74-
// Between hunks — show up to 1 trailing context line
75-
let skip = if gap_len > 1 { gap_len - 1 } else { 0 };
76-
self.orig_line += skip;
77-
self.edit_line += skip;
78-
for idx in (hunk.before.start - 1)..hunk.before.start {
79-
let s = self.input.interner[self.input.before[idx as usize]];
80-
self.write_context_line(s);
81-
}
82-
}
83-
}
67+
self.orig_line += gap_len;
68+
self.edit_line += gap_len;
8469

8570
// Interleave deleted/inserted line pairs, then emit remaining
8671
let del_count = hunk.before.len();
@@ -107,41 +92,11 @@ impl<'a> DiffBuilder<'a> {
10792
}
10893

10994
prev_before_end = hunk.before.end;
110-
prev_after_end = hunk.after.end;
11195
}
11296

11397
self.output
11498
}
11599

116-
fn write_context_line(&mut self, text: &str) {
117-
let text = text.strip_suffix('\n').unwrap_or(text);
118-
write!(
119-
self.output,
120-
"{:width$}{} ",
121-
self.orig_line,
122-
colors::gray(" |"),
123-
width = self.line_number_width
124-
)
125-
.unwrap();
126-
self.output.push_str(&fmt_rem());
127-
self.output.push_str(&fmt_rem_text(text));
128-
self.output.push('\n');
129-
self.orig_line += 1;
130-
131-
write!(
132-
self.output,
133-
"{:width$}{} ",
134-
self.edit_line,
135-
colors::gray(" |"),
136-
width = self.line_number_width
137-
)
138-
.unwrap();
139-
self.output.push_str(&fmt_add());
140-
self.output.push_str(&fmt_add_text(text));
141-
self.output.push('\n');
142-
self.edit_line += 1;
143-
}
144-
145100
fn write_rem_line(&mut self, text: &str) {
146101
let text = text.strip_suffix('\n').unwrap_or(text);
147102
write!(
@@ -179,10 +134,6 @@ fn fmt_add() -> String {
179134
colors::green_bold("+").to_string()
180135
}
181136

182-
fn fmt_add_text(x: &str) -> String {
183-
colors::green(x).to_string()
184-
}
185-
186137
fn fmt_add_text_highlight(x: &str) -> String {
187138
colors::black_on_green(x).to_string()
188139
}
@@ -191,10 +142,6 @@ fn fmt_rem() -> String {
191142
colors::red_bold("-").to_string()
192143
}
193144

194-
fn fmt_rem_text(x: &str) -> String {
195-
colors::red(x).to_string()
196-
}
197-
198145
fn fmt_rem_text_highlight(x: &str) -> String {
199146
colors::white_on_red(x).to_string()
200147
}
@@ -294,8 +241,6 @@ mod tests {
294241
"2 | -\n",
295242
"3 | -\n",
296243
"4 | -\n",
297-
"5 | -console.log(\n",
298-
"1 | +console.log(\n",
299244
"6 | -'Hello World'\n",
300245
"2 | +\"Hello World\"\n",
301246
"7 | -)\n",

0 commit comments

Comments
 (0)