(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ready: Promise<any>,
serviceManager: IServiceManager,
serviceContainer: IServiceContainer,
context: IExtensionContext
)
| 28 | export interface IExtensionApi extends Jupyter {} |
| 29 | |
| 30 | export function buildApi( |
| 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 32 | ready: Promise<any>, |
| 33 | serviceManager: IServiceManager, |
| 34 | serviceContainer: IServiceContainer, |
| 35 | context: IExtensionContext |
| 36 | ): IExtensionApi { |
| 37 | const extensions = serviceContainer.get<IExtensions>(IExtensions); |
| 38 | const envApi = serviceContainer.get<INotebookPythonEnvironmentService>(INotebookPythonEnvironmentService); |
| 39 | const api: IExtensionApi = { |
| 40 | // 'ready' will propagate the exception, but we must log it here first. |
| 41 | ready: getReady(ready), |
| 42 | registerPythonApi: (pythonApi: PythonApi) => registerPythonApi(pythonApi, serviceContainer), |
| 43 | registerRemoteServerProvider: (provider: IJupyterUriProvider) => |
| 44 | registerRemoteServerProvider(provider, serviceContainer), |
| 45 | getKernelService: () => getKernelService(serviceContainer), |
| 46 | addRemoteJupyterServer: (providerId: string, handle: string) => |
| 47 | addRemoteJupyterServer(providerId, handle, serviceContainer), |
| 48 | openNotebook: async (uri: Uri, kernelOrPythonEnvId: string | EnvironmentPath) => |
| 49 | openNotebook(uri, kernelOrPythonEnvId, serviceContainer), |
| 50 | createJupyterServerCollection: (id: string, label: string, serverProvider: JupyterServerProvider) => { |
| 51 | return createJupyterServerCollection( |
| 52 | id, |
| 53 | label, |
| 54 | serverProvider, |
| 55 | extensions.determineExtensionFromCallStack().extensionId, |
| 56 | serviceContainer |
| 57 | ); |
| 58 | }, |
| 59 | get kernels() { |
| 60 | return getKernelsApi(extensions.determineExtensionFromCallStack().extensionId); |
| 61 | }, |
| 62 | // Only for use By Python, hence this is proposed API and can change anytime. |
| 63 | // Do not add this to Kernels or other namespaces, as this is only for Python. |
| 64 | onDidChangePythonEnvironment: envApi.onDidChangeEnvironment, |
| 65 | // Only for use By Python, hence this is proposed API and can change anytime. |
| 66 | // Do not add this to Kernels or other namespaces, as this is only for Python. |
| 67 | getPythonEnvironment(uri: Uri): EnvironmentPath | undefined { |
| 68 | // This is a proposed API that is only used by the Python extension. |
| 69 | // Hence the reason to keep this separate. |
| 70 | // This way we can keep the API stable for other extensions (which would be the majority case). |
| 71 | return envApi.getPythonEnvironment(uri); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | // In test/dev environment return the DI Container. |
| 76 | if ( |
| 77 | isTestExecution() || |
| 78 | context.extensionMode === ExtensionMode.Development || |
| 79 | context.extensionMode === ExtensionMode.Test |
| 80 | ) { |
| 81 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
| 82 | (api as any).serviceContainer = serviceContainer; |
| 83 | (api as any).serviceManager = serviceManager; |
| 84 | /* eslint-enable @typescript-eslint/no-explicit-any */ |
| 85 | } |
| 86 | return api; |
| 87 | } |
no test coverage detected