From 6f962b372747c823469ab108e8bd4e55bbd95c8a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 15 May 2024 15:47:24 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20reading=20of=20unopened=20?= =?UTF-8?q?ipynb=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/src/util/ideUtils.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/src/util/ideUtils.ts b/extensions/vscode/src/util/ideUtils.ts index ce22f7b1d..e594ec98e 100644 --- a/extensions/vscode/src/util/ideUtils.ts +++ b/extensions/vscode/src/util/ideUtils.ts @@ -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 ""; } }