(filePath: string)
| 108 | } |
| 109 | |
| 110 | async function resolveNotebookFromFilePath(filePath: string) { |
| 111 | const uri = Uri.file(filePath); |
| 112 | let parsedUri = uri; |
| 113 | try { |
| 114 | parsedUri = Uri.parse(filePath); |
| 115 | } catch { |
| 116 | // |
| 117 | } |
| 118 | let notebook = |
| 119 | workspace.notebookDocuments.find( |
| 120 | // eslint-disable-next-line local-rules/dont-use-fspath |
| 121 | (doc) => doc.uri.path === filePath || doc.uri.fsPath === filePath |
| 122 | ) || |
| 123 | workspace.notebookDocuments.find((doc) => isEqual(doc.uri, uri)) || |
| 124 | workspace.notebookDocuments.find( |
| 125 | // eslint-disable-next-line local-rules/dont-use-fspath |
| 126 | (doc) => doc.uri.path === filePath || doc.uri.fsPath === parsedUri.fsPath |
| 127 | ) || |
| 128 | workspace.notebookDocuments.find((doc) => isEqual(doc.uri, parsedUri)); |
| 129 | notebook = notebook || (await workspace.openNotebookDocument(uri)); |
| 130 | if (!notebook) { |
| 131 | throw new WrappedError(`Unable to find notebook at ${filePath}.`, undefined, 'notebookNotFound'); |
| 132 | } |
| 133 | if (!isJupyterNotebook(notebook)) { |
| 134 | throw new WrappedError( |
| 135 | `The notebook at ${filePath} is not a Jupyter notebook This tool can only be used with Jupyter Notebooks.`, |
| 136 | undefined, |
| 137 | 'nonJupyterNotebook' |
| 138 | ); |
| 139 | } |
| 140 | if (!window.visibleNotebookEditors.find((e) => e.notebook === notebook)) { |
| 141 | await window.showNotebookDocument(notebook); |
| 142 | } |
| 143 | return notebook; |
| 144 | } |
no test coverage detected