Add CellOffsets abstraction (#8814)

Refactor `Notebook::cell_offsets` to use an abstract struct for storing
the cell offsets. This will allow us to add useful methods on it.
This commit is contained in:
Dhruv Manilawala 2023-11-22 09:27:00 -06:00 committed by GitHub
parent 0cb438dd65
commit 727e389cac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 16 deletions

View file

@ -9,6 +9,7 @@ use log::error;
use rustc_hash::FxHashMap;
use ruff_diagnostics::Diagnostic;
use ruff_notebook::Notebook;
use ruff_python_ast::imports::ImportMap;
use ruff_python_ast::PySourceType;
use ruff_python_codegen::Stylist;
@ -149,6 +150,7 @@ pub fn check_path(
source_type.is_ipynb(),
) {
Ok(python_ast) => {
let cell_offsets = source_kind.as_ipy_notebook().map(Notebook::cell_offsets);
if use_ast {
diagnostics.extend(check_ast(
&python_ast,
@ -173,8 +175,8 @@ pub fn check_path(
stylist,
path,
package,
source_kind,
source_type,
cell_offsets,
);
imports = module_imports;
diagnostics.extend(import_diagnostics);