Add cell indexes to all diagnostics (#9387)

## Summary

Ensures that any lint rules that include line locations render them as
relative to the cell (and include the cell number) when inside a Jupyter
notebook.

Closes https://github.com/astral-sh/ruff/issues/6672.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2024-01-04 10:02:23 -04:00 committed by GitHub
parent f0d43dafcf
commit 328262bfac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 141 additions and 25 deletions

View file

@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::fmt::{Debug, Formatter};
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;
#[cfg(feature = "serde")]
@ -253,3 +253,20 @@ impl Debug for SourceLocation {
.finish()
}
}
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum SourceRow {
/// A row within a cell in a Jupyter Notebook.
Notebook { cell: OneIndexed, line: OneIndexed },
/// A row within a source file.
SourceFile { line: OneIndexed },
}
impl Display for SourceRow {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
SourceRow::Notebook { cell, line } => write!(f, "cell {cell}, line {line}"),
SourceRow::SourceFile { line } => write!(f, "line {line}"),
}
}
}