[ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics by ntBre · Pull Request #19535 · astral-sh/ruff (original) (raw)
added internal
An internal refactor or improvement
Related to reporting of diagnostics.
labels
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 changed the title
Fix empty spans following a line terminator in Fix empty spans following a line terminator and unprintable character spans in ruff_dbruff_db
ntBre marked this pull request as ready for review
MichaReiser changed the title
Fix empty spans following a line terminator and unprintable character spans in Fix empty spans following a line terminator and unprintable character spans in Diagnosticsruff_db
MichaReiser changed the title
Fix 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
MichaReiser changed the title
Fix 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
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 deleted the brent/empty-span-after-line-terminator branch
ntBre added a commit that referenced this pull request
ntBre added a commit that referenced this pull request
dcreager added a commit that referenced this pull request
- main: (24 commits)
Add
Checker::contextmethod, deduplicate Unicode checks (#19609) [flake8-pyi] Preserve inline comment in ellipsis removal (PYI013) (#19399) [ty] Add flow diagram for import resolution [ty] Add comments to some core resolver functions [ty] Add missing ticks and use consistent quoting [ty] Reflow some long lines [ty] Unexport helper function [ty] Remove offset fromCompletionTargetTokens::Unknown[pyupgrade] FixUP030to avoid modifying double curly braces in format strings (#19378) [ty] fix a typo (#19621) [ty] synthesize__replace__for dataclasses (>=3.13) (#19545) [ty] DiscardDefinitions when normalizingSignatures (#19615) [ty] Fix empty spans following a line terminator and unprintable character spans in diagnostics (#19535) AddLinterContext::settingsto avoid passing separate settings (#19608) Support.pyifiles in ruff analyze graph (#19611) [ty] Sync vendored typeshed stubs (#19607) [ty] Bump docstring-adder pin (#19606) [perflint] Ignore rule if target isglobalornonlocal(PERF401) (#19539) Add license classifier back to pyproject.toml (#19599) [ty] Add stub mapping support to signature help (#19570) ...
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 }})