ruff/crates/ruff_annotate_snippets
Brent Westbrook 5bfffe1aa7
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
[ty] Remap Jupyter notebook cell indices in ruff_db (#19698)
## Summary

This PR remaps ranges in Jupyter notebooks from simple `row:column`
indices in the concatenated source code to `cell:row:col` to match
Ruff's output. This is probably not a likely change to land upstream in
`annotate-snippets`, but I didn't see a good way around it.

The remapping logic is taken nearly verbatim from here:


cd6bf1457d/crates/ruff_linter/src/message/text.rs (L212-L222)


## Test Plan

New `full` rendering test for a notebook

I was mainly focused on Ruff, but in local tests this also works for ty:

```
error[invalid-assignment]: Object of type `Literal[1]` is not assignable to `str`
 --> Untitled.ipynb:cell 1:3:1
  |
1 | import math
2 |
3 | x: str = 1
  | ^
  |
info: rule `invalid-assignment` is enabled by default

error[invalid-assignment]: Object of type `Literal[1]` is not assignable to `str`
 --> Untitled.ipynb:cell 2:3:1
  |
1 | import math
2 |
3 | x: str = 1
  | ^
  |
info: rule `invalid-assignment` is enabled by default
```

This isn't a duplicate diagnostic, just an unimaginative example:

```py
# cell 1
import math

x: str = 1
# cell 2
import math

x: str = 1
```
2025-08-05 14:10:35 -04:00
..
examples crates: vendor annotate-snippets crate 2025-01-15 13:37:52 -05:00
src [ty] Remap Jupyter notebook cell indices in ruff_db (#19698) 2025-08-05 14:10:35 -04:00
tests [ty] Add regression test for leading tab mis-alignment in diagnostic rendering (#18965) 2025-06-26 16:27:26 +00:00
Cargo.toml crates: vendor annotate-snippets crate 2025-01-15 13:37:52 -05:00
LICENSE-APACHE crates: vendor annotate-snippets crate 2025-01-15 13:37:52 -05:00
LICENSE-MIT crates: vendor annotate-snippets crate 2025-01-15 13:37:52 -05:00
README.md crates: vendor annotate-snippets crate 2025-01-15 13:37:52 -05:00

This is a fork of the annotate-snippets crate. The principle motivation for this fork, at the time of writing, is issue #167. Specifically, we wanted to upgrade our version of annotate-snippets, but do so without changing our diagnostic message format.

This copy of annotate-snippets is basically identical to upstream, but with an extra Level::None variant that permits skipping over a new non-optional header emitted by annotate-snippets.

More generally, it seems plausible that we may want to tweak other aspects of the output format in the future, so it might make sense to stick with our own copy so that we can be masters of our own destiny.