🐛 fix reading of unopened ipynb files

This commit is contained in:
Nate Sesti 2024-05-15 15:47:24 -07:00
parent 3f83c6a3e8
commit 6f962b3727

View file

@ -300,9 +300,13 @@ export class VsCodeIdeUtils {
// First, check whether it's a notebook document
// Need to iterate over the cells to get full contents
const notebook = vscode.workspace.notebookDocuments.find(
(doc) => doc.uri.toString() === uri.toString(),
);
const notebook =
vscode.workspace.notebookDocuments.find(
(doc) => doc.uri.toString() === uri.toString(),
) ??
(uri.fsPath.endsWith("ipynb")
? await vscode.workspace.openNotebookDocument(uri)
: undefined);
if (notebook) {
return notebook
.getCells()
@ -331,7 +335,8 @@ export class VsCodeIdeUtils {
const truncatedBytes = bytes.slice(0, VsCodeIdeUtils.MAX_BYTES);
const contents = new TextDecoder().decode(truncatedBytes);
return contents;
} catch {
} catch (e) {
console.warn("Error reading file", e);
return "";
}
}