-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notebook kernels #101963
Comments
As we need to support dynamic kernel registration and potentially support kernels per document, one proposal is provider-like api. The shape and concepts of the API would be similar to Code Actions to some extent (a provider can provide code fixes for code ranges in a document, and users can pick code fixes from all providers, or quickly apply fixes if there is a preferred fix). Let's sketch and see if it meets the requirements. Firstly, extensions can register kernel providers for a notebook document by export interface NotebookDocumentFilter {
viewType?: string;
filenamePattern?: GlobPattern;
excludeFileNamePattern?: GlobPattern;
}
export function registerNotebookKernelProvider(
selector: NotebookDocumentFilter,
provider: NotebookKernelProvider
): Disposable; The kernel provider is responsible for
export interface NotebookKernelProvider<T extends NotebookKernel = NotebookKernel> {
onDidChangeKernels?: Event<void>;
provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
resolveKernel?(kernel: T, document: NotebookDocument, webview: NotebookCommunication, token: CancellationToken): ProviderResult<T>;
} A notebook kernel contains following information
export interface NotebookKernel {
label: string;
description?: string;
preloads?: Uri[];
isPreferred?: boolean;
executeCell(document: NotebookDocument, cell: NotebookCell, token: CancellationToken): Promise<void>;
executeAllCells(document: NotebookDocument, token: CancellationToken): Promise<void>;
} Lastly the extensions can listen to active kernel change event if it wants to any kind of clean up when a kernel becomes disconnected. export namespace notebook {
export let activeNotebookKernel: NotebookKernel | undefined;
export const onDidChangeActiveKernel: Event<void>;
} With this provider like API, all available kernels for a document would be listed in a flat list if there are more than one kernels. For simple scenarios like GitHub Issue Notebook, the extension will contribute both content provider and kernel provider, which provides a preferred kernel, and then the kernel can be automatically selected and users won't be bothered by it. Check listThis proposal meets the criteria listed above
|
Reads nicely!
That's a notebook document, right? I wonder if document selector is the right thing as it is often associated with selecting a language. Maybe we should introduce a notebook selector - which is similar but allows to select a notebook view type. |
Good suggestion, updated the proposal accordingly. |
The API proposal above meets the requirements for resolving available notebook kernels from multiple kernel providers but while adopting this in Jupyter notebooks, we (@DonJayamanne, me and more) found that it's challenging to implement a Jupyter compliant notebook kernel provider as Jupyter stores kernel information in every document. In other words, traditional Jupyter stores user's kernel selection directly in notebook documents. It's not clear who is the source of truth of kernel selection with current proposal. The problem can be tackled in multiple approaches, one of them is changing the semantics of
Scenarios: 1. Content provider and single kernel from the same extension
2. Content provider and multiple kernels from the same extension
3. Content provider and multiple kernels from extension A, additional kernel providers from extension B
4. Content provider from extension A, kernel providers from extension B and C
|
We introduced the concept of
vscode.NotebookKernel
previously to allow multiple notebook execution contributions and the responsibilities of Content Provider, Renderer and Kernels are much more clear. The proposal we had was a provider like kernel contribution:Extensions can register kernels for specific files (filtered by
selectors: GlobPattern[]
, e.g.,*.ipynb
), it works fine for simple cases (like GitHub Issue Notebook, which only has one kernel for all*.github-issues
files). However it's not clear how multiple kernels contribution really work with this API, here are scenarios we need to take into accounts when polishing the design of the kernel APIcontribtions
inpackage.json
) but sometimes extensions can know what kernels are available only after it's activated.resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Promise<void>;
The text was updated successfully, but these errors were encountered: