mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:52:01 +00:00
Handle non-printable characters in diff view (#11687)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
ee1621b2f9
commit
ed947792cf
9 changed files with 82 additions and 59 deletions
|
@ -10,6 +10,7 @@ use ruff_diagnostics::{Applicability, Fix};
|
|||
use ruff_source_file::{OneIndexed, SourceFile};
|
||||
|
||||
use crate::message::Message;
|
||||
use crate::text_helpers::ShowNonprinting;
|
||||
|
||||
/// Renders a diff that shows the code fixes.
|
||||
///
|
||||
|
@ -101,6 +102,7 @@ impl Display for Diff<'_> {
|
|||
)?;
|
||||
|
||||
for (emphasized, value) in change.iter_strings_lossy() {
|
||||
let value = value.show_nonprinting();
|
||||
if emphasized {
|
||||
write!(f, "{}", line_style.apply_to(&value).underline().on_black())?;
|
||||
} else {
|
||||
|
|
|
@ -17,6 +17,7 @@ use crate::message::diff::Diff;
|
|||
use crate::message::{Emitter, EmitterContext, Message};
|
||||
use crate::registry::AsRule;
|
||||
use crate::settings::types::UnsafeFixes;
|
||||
use crate::text_helpers::ShowNonprinting;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Default)]
|
||||
|
@ -251,6 +252,8 @@ impl Display for MessageCodeFrame<'_> {
|
|||
range - start_offset,
|
||||
);
|
||||
|
||||
let source_text = source.text.show_nonprinting();
|
||||
|
||||
let start_char = source.text[TextRange::up_to(source.annotation_range.start())]
|
||||
.chars()
|
||||
.count();
|
||||
|
@ -262,7 +265,7 @@ impl Display for MessageCodeFrame<'_> {
|
|||
let snippet = Snippet {
|
||||
title: None,
|
||||
slices: vec![Slice {
|
||||
source: &source.text,
|
||||
source: &source_text,
|
||||
line_start: self.notebook_index.map_or_else(
|
||||
|| start_index.get(),
|
||||
|notebook_index| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue