Skip to content

Commit

Permalink
Compute NotebookIndex to Diagnostics on stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Sep 26, 2023
1 parent 404b53e commit a91285c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/ruff_cli/src/diagnostics.rs
Expand Up @@ -8,7 +8,7 @@ use std::ops::AddAssign;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;

use anyhow::{anyhow, Context, Result};
use anyhow::{Context, Result};
use colored::Colorize;
use filetime::FileTime;
use log::{debug, error, warn};
Expand Down Expand Up @@ -343,9 +343,7 @@ pub(crate) fn lint_path(

let notebook_indexes = if let SourceKind::IpyNotebook(notebook) = source_kind {
FxHashMap::from_iter([(
path.to_str()
.ok_or_else(|| anyhow!("Unable to parse filename: {:?}", path))?
.to_string(),
path.to_string_lossy().to_string(),
// Index needs to be computed always to store in cache.
notebook.index().clone(),
)])
Expand Down Expand Up @@ -474,14 +472,24 @@ pub(crate) fn lint_stdin(
);
}

let notebook_indexes = if let SourceKind::IpyNotebook(notebook) = source_kind {
FxHashMap::from_iter([(
path.map_or_else(|| "-".into(), |path| path.to_string_lossy().to_string()),
// Index needs to be computed always to store in cache.
notebook.index().clone(),
)])
} else {
FxHashMap::default()
};

Ok(Diagnostics {
messages,
fixed: FxHashMap::from_iter([(
fs::relativize_path(path.unwrap_or_else(|| Path::new("-"))),
fixed,
)]),
imports,
notebook_indexes: FxHashMap::default(),
notebook_indexes,
})
}

Expand Down

0 comments on commit a91285c

Please sign in to comment.