Skip to content

Commit 212d620

Browse files
committed
fix: Show suggestion if same as source
1 parent dbf9101 commit 212d620

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/renderer/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use std::borrow::Cow;
5555
use std::cmp::{max, min, Ordering, Reverse};
5656
use std::collections::{HashMap, VecDeque};
5757
use std::fmt;
58-
use std::ops::Range;
5958
use stylesheet::Stylesheet;
6059

6160
const ANONYMIZED_LINE_NUM: &str = "LL";
@@ -1911,9 +1910,7 @@ impl Renderer {
19111910
assert!(underline_start >= 0 && underline_end >= 0);
19121911
let padding: usize = max_line_num_len + 3;
19131912
for p in underline_start..underline_end {
1914-
if matches!(show_code_change, DisplaySuggestion::Underline)
1915-
&& is_different(sm, &part.replacement, part.span.clone())
1916-
{
1913+
if matches!(show_code_change, DisplaySuggestion::Underline) {
19171914
// If this is a replacement, underline with `~`, if this is an addition
19181915
// underline with `+`.
19191916
buffer.putc(
@@ -2955,14 +2952,6 @@ struct UnderlineParts {
29552952
multiline_bottom_right_with_text: char,
29562953
}
29572954

2958-
/// Whether the original and suggested code are the same.
2959-
pub(crate) fn is_different(sm: &SourceMap<'_>, suggested: &str, range: Range<usize>) -> bool {
2960-
match sm.span_to_snippet(range) {
2961-
Some(s) => s != suggested,
2962-
None => true,
2963-
}
2964-
}
2965-
29662955
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29672956
pub enum OutputTheme {
29682957
Ascii,

src/renderer/source_map.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::renderer::{char_width, is_different, num_overlap, LineAnnotation, LineAnnotationType};
1+
use crate::renderer::{char_width, num_overlap, LineAnnotation, LineAnnotationType};
22
use crate::{Annotation, AnnotationKind, Patch};
33
use std::borrow::Cow;
44
use std::cmp::{max, min};
@@ -474,16 +474,10 @@ impl<'a> SourceMap<'a> {
474474
_ => 1,
475475
})
476476
.sum();
477-
if !is_different(self, &part.replacement, part.span.clone()) {
478-
// Account for cases where we are suggesting the same code that's already
479-
// there. This shouldn't happen often, but in some cases for multipart
480-
// suggestions it's much easier to handle it here than in the origin.
481-
} else {
482-
line_highlight.push(SubstitutionHighlight {
483-
start: (cur_lo.char as isize + acc) as usize,
484-
end: (cur_lo.char as isize + acc + len) as usize,
485-
});
486-
}
477+
line_highlight.push(SubstitutionHighlight {
478+
start: (cur_lo.char as isize + acc) as usize,
479+
end: (cur_lo.char as isize + acc + len) as usize,
480+
});
487481
buf.push_str(&part.replacement);
488482
// Account for the difference between the width of the current code and the
489483
// snippet being suggested, so that the *later* suggestions are correctly

tests/formatter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,9 @@ LL | .sum::<_>() //~ ERROR type annotations needed
29972997
| ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
29982998
|
29992999
help: consider specifying the generic argument
3000+
|
3001+
LL | .sum::<_>() //~ ERROR type annotations needed
3002+
|
30003003
"#]];
30013004
let renderer = Renderer::plain().anonymized_line_numbers(true);
30023005
assert_data_eq!(renderer.render(input), expected);

0 commit comments

Comments
 (0)