Rollup merge of #121107 - estebank:capitalization-suggestion, r=michaelwoerister

Fix msg for verbose suggestions with confusable capitalization

When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
This commit is contained in:
Guillaume Gomez 2024-02-15 14:33:02 +01:00 committed by GitHub
commit 3c8705402a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 26 additions and 24 deletions

View file

@ -320,7 +320,9 @@ impl CodeSuggestion {
// We need to keep track of the difference between the existing code and the added
// or deleted code in order to point at the correct column *after* substitution.
let mut acc = 0;
let mut only_capitalization = false;
for part in &substitution.parts {
only_capitalization |= is_case_difference(sm, &part.snippet, part.span);
let cur_lo = sm.lookup_char_pos(part.span.lo());
if prev_hi.line == cur_lo.line {
let mut count =
@ -393,7 +395,6 @@ impl CodeSuggestion {
}
}
highlights.push(std::mem::take(&mut line_highlight));
let only_capitalization = is_case_difference(sm, &buf, bounding_span);
// if the replacement already ends with a newline, don't print the next line
if !buf.ends_with('\n') {
push_trailing(&mut buf, prev_line.as_ref(), &prev_hi, None);