Skip to content
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

Register arbritrary kernel languages with docRegistry #1188

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,14 @@ const extension: JupyterFrontEndPlugin<void> = {
);

// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, IFileTypeData[]>,
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(
{
Expand Down
Loading