diff --git a/jupyterlab/packages/jupyterlab-jupytext-extension/src/index.ts b/jupyterlab/packages/jupyterlab-jupytext-extension/src/index.ts index df41155a..c8e47b37 100644 --- a/jupyterlab/packages/jupyterlab-jupytext-extension/src/index.ts +++ b/jupyterlab/packages/jupyterlab-jupytext-extension/src/index.ts @@ -363,15 +363,14 @@ const extension: JupyterFrontEndPlugin = { ); // Register Jupytext text notebooks file types - registerFileTypes(docRegistry, trans); + registerFileTypes(availableKernelLanguages, docRegistry, trans); // Get all kernel file types to add to Jupytext factory const kernelLanguageNames = []; - for (const kernelLanguages of availableKernelLanguages.values()) { - for (const kernelLanguage of kernelLanguages) { - kernelLanguageNames.push(kernelLanguage.kernelName); - } + for (const kernelLanguage of availableKernelLanguages.keys()) { + kernelLanguageNames.push(kernelLanguage); } + // Create a factory for Jupytext createFactory( kernelLanguageNames, diff --git a/jupyterlab/packages/jupyterlab-jupytext-extension/src/registry.ts b/jupyterlab/packages/jupyterlab-jupytext-extension/src/registry.ts index 5a628c9a..a1b02bb1 100644 --- a/jupyterlab/packages/jupyterlab-jupytext-extension/src/registry.ts +++ b/jupyterlab/packages/jupyterlab-jupytext-extension/src/registry.ts @@ -2,12 +2,35 @@ import { DocumentRegistry } from '@jupyterlab/docregistry'; import { TranslationBundle } from '@jupyterlab/translation'; -import { markdownIcon } from '@jupyterlab/ui-components'; +import { markdownIcon, kernelIcon } from '@jupyterlab/ui-components'; + +import { IFileTypeData } from './tokens'; export function registerFileTypes( + availableKernelLanguages: Map, docRegistry: DocumentRegistry, trans: TranslationBundle ) { + // Add kernel file types to registry + availableKernelLanguages.forEach( + (kernelFileTypes: IFileTypeData[], kernelLanguage: string) => { + // Do not add python as it will be already there by default + if (kernelLanguage !== 'python') { + kernelFileTypes.map((kernelFileType) => { + docRegistry.addFileType({ + name: kernelLanguage, + contentType: 'file', + displayName: trans.__( + kernelFileType.paletteLabel.split('New')[1].trim() + ), + extensions: [`.${kernelFileType.fileExt}`], + icon: kernelFileType.kernelIcon || kernelIcon, + }); + }); + } + } + ); + // Add markdown file types to registry docRegistry.addFileType( {