question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with IFileBrowserFactory and ICommandPalette

See original GitHub issue

I encounter an error and blocked when developed my jupyterlab extension and tried to reproduce it with the official jlab extension example. For this extension-examples/launcher: I found that if I add ICommandPalette to the requires like :

  requires: [IFileBrowserFactory, ICommandPalette],
  optional: [ILauncher, IMainMenu],

instead of:

  requires: [IFileBrowserFactory],
  optional: [ILauncher, IMainMenu, ICommandPalette],

The rest of the code is identical, the plugin will be failed to activate and console shows:

Plugin 'launcher' failed to activate.
TypeError: launcher.add is not a function
    at activate (index.js:48)
    at jlab_core.ec15f8c091a46864d4c7.js:formatted:59045
    at async Promise.all (:8888/lab/workspaces/index 101)

So seems that ICommandPalette cannot be in ‘requires’ along with IFileBrowserFactory. So the Question is, for my use case: When click on this command (from command palette and in menu.fileMenu)then I can get opened file(.py, .md, .ipynb …) local path. I have done the most part of this extension but currently blocked by how to retrieve the current opened file path in the code block:

commands.addCommand(command, {
      label: 'xxx',
      caption: 'xxx,
      icon: args => (args['isPalette'] ? null : icon),
      execute: async args => {
         ...

I was thinking that something like this:

const extension: JupyterFrontEndPlugin<void> = {
  id: 'main-menu',
  autoStart: true,
  requires: [ICommandPalette, IMainMenu, IFileBrowserFactory],
  activate: (
    app: JupyterFrontEnd,
    browserFactory: IFileBrowserFactory,
    palette: ICommandPalette,
    mainMenu: IMainMenu,
    trans: ITranslator
  ) => {
commands.addCommand(command, {
      label: 'xxxx',
      caption: 'xxxx',
      icon: args => (args['isPalette'] ? null : icon),
      execute: async args => {
         const path = browserFactory.defaultBrowser.model.path;
         console.log(path);

But like I mentioned at the very beginning, I cannot make IFileBrowserFactory and ICommandPalette at ‘requires’ field at the same time. any idea for how to achieve above functionality?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasongroutcommented, Jan 21, 2021

The arguments to the activate function are the requires services, then the optional services, in order. When you moved the command palette to the requires, you changed the order of the services passed into your activate function. You need to also change the order of the parameters in your activate function arguments.

For example, with your change:

  requires: [IFileBrowserFactory, ICommandPalette],
  optional: [ILauncher, IMainMenu],

the order of services passed to the activate function would be IFileBrowserFactory, ICommandPalette, ILauncher, IMainMenu

0reactions
danny95333commented, Jan 21, 2021

nvm, issue resolved! Thanks for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jupyterlab/index.ts at master - filebrowser-extension - GitHub
ICommandPalette. ],. provides: IFileBrowserCommands,. autoStart: true,. activate: async (. app: JupyterFrontEnd,. factory: IFileBrowserFactory,.
Read more >
Common Extension Points - JupyterLab Documentation
In order to add an existing, registered command to the command palette, you need to request the ICommandPalette token in your extension. Here...
Read more >
How to render a notebook with voila in a self-implemented ...
I'd like to create a personal Jupyter Lab extension to add a button to the Launcher. When clicking on it, it should render...
Read more >
How to use the @jupyterlab/console.ConsolePanel ... - Snyk
... provides: IConsoleTracker, requires: [ IMainMenu, ICommandPalette, ConsolePanel.IContentFactory, IEditorServices, ILayoutRestorer, IFileBrowserFactory, ...
Read more >
"Open from URL" as URL Parameter - Jupyter Community Forum
... activate: (; app: JupyterFrontEnd,; factory: IFileBrowserFactory,; translator: ITranslator,; palette: ICommandPalette | null; ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found