[ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics by ntBre · Pull Request #19535 · astral-sh/ruff (original) (raw)

@ntBre added internal

An internal refactor or improvement

diagnostics

Related to reporting of diagnostics.

labels

Jul 24, 2025

ntBre

@ntBre

@ntBre

@ntBre

@ntBre

@ntBre

@ntBre

@ntBre

@ntBre

@ntBre

the original implementation used the input range in update_range, which I didn't notice, so I was double-updating the new ranges and eventually causing a panic from an invalid byte offset

@ntBre

@ntBre

@ntBre ntBre changed the titleFix empty spans following a line terminator in ruff_db Fix empty spans following a line terminator and unprintable character spans in ruff_db

Jul 25, 2025

@ntBre ntBre marked this pull request as ready for review

July 25, 2025 19:47

@MichaReiser MichaReiser changed the titleFix empty spans following a line terminator and unprintable character spans in ruff_db Fix empty spans following a line terminator and unprintable character spans in Diagnostics

Jul 26, 2025

@MichaReiser MichaReiser changed the titleFix empty spans following a line terminator and unprintable character spans in Diagnostics Fix empty spans following a line terminator and unprintable character spans in diagnostics

Jul 26, 2025

MichaReiser

MichaReiser

@MichaReiser MichaReiser changed the titleFix empty spans following a line terminator and unprintable character spans in diagnostics [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics

Jul 26, 2025

BurntSushi

@ntBre

We can just track this as the offset between the original source length and the current or result length. This offset is given by:

let offset = result.text_len().to_usize() - index;

which when added to the original update_ranges call:

update_ranges(index + offset, tab_width);

simplifies to just result.text_len() (index is added and then subtracted).

The other slight nuance here is that in the original update_ranges call locations, we would also need to subtract the length of the new character from the index argument, so I instead opted just to move the calls to before we added the new character. This makes result.text_len() alone exactly the value we need.

@ntBre ntBre deleted the brent/empty-span-after-line-terminator branch

July 29, 2025 12:26

ntBre added a commit that referenced this pull request

Jul 30, 2025

@ntBre

ntBre added a commit that referenced this pull request

Jul 30, 2025

@ntBre

dcreager added a commit that referenced this pull request

Aug 1, 2025

@dcreager

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})