MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / resolveNotebookFromFilePath

Function resolveNotebookFromFilePath

src/standalone/chat/helper.ts:110–144  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

108}
109
110async 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}

Callers 2

invokeFunction · 0.85
prepareInvocationFunction · 0.85

Calls 4

isJupyterNotebookFunction · 0.90
openNotebookDocumentMethod · 0.80
parseMethod · 0.65
fileMethod · 0.45

Tested by

no test coverage detected