Skip to content

Commit

Permalink
fixed issue with console conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Meriem-BenIsmail committed Mar 26, 2024
1 parent 77f1bd9 commit b5295c2
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { Menu } from '@lumino/widgets';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IMainMenu } from '@jupyterlab/mainmenu';
import { EditorLanguageRegistry } from '@jupyterlab/codemirror';
import { ConsolePanel } from '@jupyterlab/console';
import { SessionContext } from '@jupyterlab/apputils';

function addKernelMenuItems(
app: any,
serviceManager: any,
palette: any,
mainMenu: IMainMenu
) {
const { commands, shell } = app;
const { commands } = app;
const menu = new Menu({ commands: app.commands });
menu.title.label = 'Available Kernels Menu';
mainMenu.addMenu(menu);

Object.entries(serviceManager.kernelspecs.specs.kernelspecs).forEach(
([key, value]: [string, any]) => {
let count: number = 0;
const kernelMenu = new Menu({ commands: app.commands });
kernelMenu.title.label = value.display_name;
const language =
Expand All @@ -33,6 +33,7 @@ function addKernelMenuItems(
});

const startNotebookCommand = `widgets:start-notebook-${key}`;

commands.addCommand(startNotebookCommand, {
label: `New ${key} notebook`,
execute: async () => {
Expand All @@ -49,47 +50,17 @@ function addKernelMenuItems(
});
}
});
let contentFactory: ConsolePanel.IContentFactory;

const startConsoleCommand = `widgets:start-console-${key}`;

commands.addCommand(startConsoleCommand, {
label: `New ${key} console`,
execute: async () => {
count++;
try {
const sessionManager = app.serviceManager.sessions;
const specsManager = app.serviceManager.kernelspecs;

const rendermime = app.rendermime;
const manager = app.shell.widgets;
const mimeTypeService = app.docRegistry.mimeTypeService;

const kernelName = key;
console.log(kernelName);

const sessionContext = new SessionContext({
sessionManager: sessionManager,
specsManager: specsManager,
kernelPreference: await sessionManager.startNew({
name: `${kernelName} console`,
kernel: { name: kernelName },
type: 'console',
path: '.'
})
});
sessionContext.changeKernel();

console.log(sessionContext.kernelPreference);

await sessionContext.ready;
const panel = new ConsolePanel({
rendermime: rendermime,
contentFactory: contentFactory,
manager: manager,
mimeTypeService: mimeTypeService,
sessionContext: sessionContext
await commands.execute('console:create', {
name: `Console ${count}`,
kernelPreference: { name: key }
});
shell.add(panel, 'main');
shell.activateById(panel.id);
} catch (error) {
console.error('Error starting console:', error);
}
Expand Down

0 comments on commit b5295c2

Please sign in to comment.