From 4c2e6e820af254164be90b51fde7b1c69a897fcc Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 26 Sep 2023 11:46:18 +0530 Subject: [PATCH] Compute `NotebookIndex` to `Diagnostics` on stdin --- crates/ruff_cli/src/diagnostics.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/ruff_cli/src/diagnostics.rs b/crates/ruff_cli/src/diagnostics.rs index ed4455786132f4..bb70e363b9d11d 100644 --- a/crates/ruff_cli/src/diagnostics.rs +++ b/crates/ruff_cli/src/diagnostics.rs @@ -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(), )]) @@ -474,6 +472,16 @@ 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([( @@ -481,7 +489,7 @@ pub(crate) fn lint_stdin( fixed, )]), imports, - notebook_indexes: FxHashMap::default(), + notebook_indexes, }) }