(
uri: Uri,
kernelOrPythonEnvId: string | EnvironmentPath,
serviceContainer: IServiceContainer
)
| 117 | } |
| 118 | |
| 119 | export async function openNotebook( |
| 120 | uri: Uri, |
| 121 | kernelOrPythonEnvId: string | EnvironmentPath, |
| 122 | serviceContainer: IServiceContainer |
| 123 | ) { |
| 124 | const extensions = serviceContainer.get<IExtensions>(IExtensions); |
| 125 | sendTelemetryEvent(Telemetry.JupyterApiUsage, undefined, { |
| 126 | clientExtId: extensions.determineExtensionFromCallStack().extensionId, |
| 127 | pemUsed: 'openNotebook' |
| 128 | }); |
| 129 | const controllers = serviceContainer.get<IControllerRegistration>(IControllerRegistration); |
| 130 | const kernelId = typeof kernelOrPythonEnvId === 'string' ? kernelOrPythonEnvId : undefined; |
| 131 | const pythonEnv = typeof kernelOrPythonEnvId === 'string' ? undefined : kernelOrPythonEnvId; |
| 132 | let id = kernelId && controllers.all.find((controller) => controller.id === kernelOrPythonEnvId)?.id; |
| 133 | if (!id && pythonEnv && !isWeb()) { |
| 134 | // Look for a python environment with this id. |
| 135 | id = controllers.all.find( |
| 136 | (controller) => |
| 137 | controller.kind === 'startUsingPythonInterpreter' && controller.interpreter.id === pythonEnv.id |
| 138 | )?.id; |
| 139 | if (!id) { |
| 140 | // Controller has not yet been created. |
| 141 | const selector = serviceContainer.get<ILocalPythonNotebookKernelSourceSelector>( |
| 142 | ILocalPythonNotebookKernelSourceSelector |
| 143 | ); |
| 144 | const connection = await selector.getKernelConnection(pythonEnv); |
| 145 | id = connection && controllers.all.find((controller) => controller.id === connection?.id)?.id; |
| 146 | } |
| 147 | } |
| 148 | if (!id) { |
| 149 | throw new Error(`Kernel ${kernelOrPythonEnvId} not found.`); |
| 150 | } |
| 151 | const notebookEditor = |
| 152 | window.activeNotebookEditor?.notebook?.uri?.toString() === uri.toString() |
| 153 | ? window.activeNotebookEditor |
| 154 | : await window.showNotebookDocument(await workspace.openNotebookDocument(uri)); |
| 155 | await commands.executeCommand('notebook.selectKernel', { |
| 156 | notebookEditor, |
| 157 | id, |
| 158 | extension: JVSC_EXTENSION_ID |
| 159 | }); |
| 160 | return notebookEditor.notebook; |
| 161 | } |
no test coverage detected