123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import {
- ILayoutRestorer,
- JupyterFrontEnd,
- JupyterFrontEndPlugin
- } from '@jupyterlab/application';
- import { WidgetTracker, MainAreaWidget } from '@jupyterlab/apputils';
- import { IConsoleTracker } from '@jupyterlab/console';
- import { IStateDB } from '@jupyterlab/coreutils';
- import { IEditorTracker } from '@jupyterlab/fileeditor';
- import { INotebookTracker } from '@jupyterlab/notebook';
- import { Debugger } from './debugger';
- import { DebuggerSidebar } from './sidebar';
- import { IDebugger } from './tokens';
- /**
- * The command IDs used by the debugger plugin.
- */
- export namespace CommandIDs {
- export const create = 'debugger:create';
- export const debugConsole = 'debugger:debug-console';
- export const debugFile = 'debugger:debug-file';
- export const debugNotebook = 'debugger:debug-notebook';
- }
- /**
- * A plugin that provides visual debugging support for consoles.
- */
- const consoles: JupyterFrontEndPlugin<void> = {
- id: '@jupyterlab/debugger:consoles',
- autoStart: true,
- requires: [IDebugger],
- optional: [IConsoleTracker],
- activate: (_, debug, tracker: IConsoleTracker | null) => {
- if (!tracker) {
- console.log(`${consoles.id} load failed. There is no console tracker.`);
- return;
- }
- console.log(`${consoles.id} has not been implemented.`, debug);
- }
- };
- /**
- * A plugin that provides visual debugging support for file editors.
- */
- const files: JupyterFrontEndPlugin<void> = {
- id: '@jupyterlab/debugger:files',
- autoStart: true,
- optional: [IEditorTracker],
- activate: (app: JupyterFrontEnd, tracker: IEditorTracker | null) => {
- app.commands.addCommand(CommandIDs.debugFile, {
- execute: async _ => {
- if (!tracker || !tracker.currentWidget) {
- return;
- }
- if (tracker.currentWidget) {
- // TODO: Find if the file is backed by a kernel or attach it to one.
- const widget = await app.commands.execute(CommandIDs.create);
- app.shell.add(widget, 'main');
- }
- }
- });
- }
- };
- /**
- * A plugin that provides visual debugging support for notebooks.
- */
- const notebooks: JupyterFrontEndPlugin<void> = {
- id: '@jupyterlab/debugger:notebooks',
- autoStart: true,
- requires: [IDebugger],
- optional: [INotebookTracker],
- activate: (_, debug, tracker: INotebookTracker | null) => {
- if (!tracker) {
- console.log(`${notebooks.id} load failed. There is no notebook tracker.`);
- return;
- }
- console.log(`${notebooks.id} has not been implemented.`, debug);
- }
- };
- /**
- * A plugin providing a condensed sidebar UI for debugging.
- */
- const sidebar: JupyterFrontEndPlugin<void> = {
- id: '@jupyterlab/debugger:sidebar',
- optional: [ILayoutRestorer],
- autoStart: true,
- activate: (app: JupyterFrontEnd, restorer: ILayoutRestorer | null) => {
- const { shell } = app;
- const label = 'Environment';
- const namespace = 'jp-debugger-sidebar';
- const sidebar = new DebuggerSidebar(null);
- sidebar.id = namespace;
- sidebar.title.label = label;
- shell.add(sidebar, 'right', { activate: false });
- if (restorer) {
- restorer.add(sidebar, sidebar.id);
- }
- }
- };
- /**
- * A plugin providing a tracker code debuggers.
- */
- const tracker: JupyterFrontEndPlugin<IDebugger> = {
- id: '@jupyterlab/debugger:tracker',
- optional: [ILayoutRestorer],
- requires: [IStateDB],
- provides: IDebugger,
- autoStart: true,
- activate: (
- app: JupyterFrontEnd,
- state: IStateDB,
- restorer: ILayoutRestorer | null
- ): IDebugger => {
- const tracker = new WidgetTracker<MainAreaWidget<Debugger>>({
- namespace: 'debugger'
- });
- app.commands.addCommand(CommandIDs.create, {
- execute: args => {
- const id = (args.id as string) || '';
- if (tracker.find(widget => id === widget.content.model.id)) {
- return;
- }
- const widget = new MainAreaWidget({
- content: new Debugger({ connector: state, id })
- });
- void tracker.add(widget);
- return widget;
- }
- });
- if (restorer) {
- // Handle state restoration.
- void restorer.restore(tracker, {
- command: CommandIDs.create,
- args: widget => ({ id: widget.content.model.id }),
- name: widget => widget.content.model.id
- });
- }
- return tracker;
- }
- };
- /**
- * Export the plugins as default.
- */
- const plugins: JupyterFrontEndPlugin<any>[] = [
- consoles,
- files,
- notebooks,
- sidebar,
- tracker
- ];
- export default plugins;
|