Skip to content

File editor extension does not add a launcher card when a spec is added after launch #17549

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

Closed
jtpio opened this issue May 6, 2025 · 1 comment · Fixed by #17550
Closed
Labels

Comments

@jtpio
Copy link
Member

jtpio commented May 6, 2025

Description

Currently the @jupyterlab/fileeditor-extension adds new cards to the launcher for some known types to create new Python, R and Julia files:

// Use available kernels to determine which common file types should have 'Create New' options in the Launcher, File Editor palette, and File menu
const getAvailableKernelFileTypes = async (): Promise<Set<IFileTypeData>> => {
const specsManager = app.serviceManager.kernelspecs;
await specsManager.ready;
let fileTypes = new Set<IFileTypeData>();
const specs = specsManager.specs?.kernelspecs ?? {};
Object.keys(specs).forEach(spec => {
const specModel = specs[spec];
if (specModel) {
const exts = commonLanguageFileTypeData.get(specModel.language);
exts?.forEach(ext => fileTypes.add(ext));
}
});
return fileTypes;
};

This function is used here in the plugin:

getAvailableKernelFileTypes()
.then(availableKernelFileTypes => {
if (launcher) {
Commands.addKernelLanguageLauncherItems(
launcher,
trans,
availableKernelFileTypes
);
}
if (palette) {
Commands.addKernelLanguagePaletteItems(
palette,
trans,
availableKernelFileTypes
);
}
if (menu) {
Commands.addKernelLanguageMenuItems(menu, availableKernelFileTypes);
}
})
.catch((reason: Error) => {
console.error(reason.message);
});

However it does not react to specs added later via the specsChanged signal. So only the notebook and console sections are correctly updated when a new spec is available.

Reproduce

  1. Uninstall ipykernel
  2. Start JupyterLab. The launcher does not have a way to create Python files and notebooks
  3. Install ipykernel
  4. Wait for the kernel specs to automatically refresh
  5. Only the notebook and console sections have the python card
jupyterlab-dynamic-launcher-card-python.mp4

Expected behavior

The "Other" category should also have the Python card after the specs have been refreshed.

Context

Noticed downstream in jupyterlite/jupyterlite#1642 (via jupyterlite/pyodide-kernel#177) with the Pyodide kernel being added after the launcher plugin has been activated.

@jtpio jtpio added bug status:Needs Triage Applied to new issues that need triage labels May 6, 2025
@jtpio
Copy link
Member Author

jtpio commented May 6, 2025

For reference the notebook extension properly handles new kernel specs:

// Add a launcher item if the launcher is available.
if (launcher) {
void services.ready.then(() => {
let disposables: DisposableSet | null = null;
const onSpecsChanged = () => {
if (disposables) {
disposables.dispose();
disposables = null;
}
const specs = services.kernelspecs.specs;
if (!specs) {
return;
}
disposables = new DisposableSet();
for (const name in specs.kernelspecs) {
const rank = name === specs.default ? 0 : Infinity;
const spec = specs.kernelspecs[name]!;
const kernelIconUrl =
spec.resources['logo-svg'] || spec.resources['logo-64x64'];
disposables.add(
launcher.add({
command: CommandIDs.createNew,
args: { isLauncher: true, kernelName: name },
category: trans.__('Notebook'),
rank,
kernelIconUrl,
metadata: {
kernel: JSONExt.deepCopy(
spec.metadata || {}
) as ReadonlyJSONValue
}
})
);
}
};
onSpecsChanged();
services.kernelspecs.specsChanged.connect(onSpecsChanged);
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants