debugger.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { CodeEditor } from '@jupyterlab/codeeditor';
  4. import { DebugService } from './service';
  5. import { DebuggerEditors } from './editors';
  6. import { DebuggerSidebar } from './sidebar';
  7. import { ReadonlyJSONValue } from '@phosphor/coreutils';
  8. import { IClientSession } from '@jupyterlab/apputils';
  9. import { IDisposable } from '@phosphor/disposable';
  10. import { Message } from '@phosphor/messaging';
  11. import { ISignal, Signal } from '@phosphor/signaling';
  12. import { SplitPanel } from '@phosphor/widgets';
  13. import { IObservableString } from '@jupyterlab/observables';
  14. import { IDebugger } from './tokens';
  15. import { IDataConnector } from '@jupyterlab/coreutils';
  16. export class Debugger extends SplitPanel {
  17. constructor(options: Debugger.IOptions) {
  18. super({ orientation: 'horizontal' });
  19. this.title.label = 'Debugger';
  20. this.title.iconClass = 'jp-BugIcon';
  21. this.model = new Debugger.Model(options);
  22. this.sidebar = new DebuggerSidebar();
  23. this.model.sidebar = this.sidebar;
  24. this.service = new DebugService(this.model);
  25. const { editorFactory } = options;
  26. this.editors = new DebuggerEditors({ editorFactory });
  27. this.addWidget(this.editors);
  28. this.addClass('jp-Debugger');
  29. }
  30. readonly editors: DebuggerEditors;
  31. readonly model: Debugger.Model;
  32. readonly sidebar: DebuggerSidebar;
  33. readonly service: DebugService;
  34. dispose(): void {
  35. if (this.isDisposed) {
  36. return;
  37. }
  38. this.model.dispose();
  39. this.service.dispose();
  40. super.dispose();
  41. }
  42. protected onAfterAttach(msg: Message) {
  43. this.addWidget(this.sidebar);
  44. this.sidebar.show();
  45. }
  46. }
  47. /**
  48. * A namespace for `Debugger` statics.
  49. */
  50. export namespace Debugger {
  51. export interface IOptions {
  52. editorFactory: CodeEditor.Factory;
  53. connector?: IDataConnector<ReadonlyJSONValue>;
  54. id?: string;
  55. session?: IClientSession;
  56. }
  57. export class Model implements IDisposable {
  58. constructor(options: Debugger.Model.IOptions) {
  59. this.connector = options.connector || null;
  60. this.id = options.id;
  61. void this._populate();
  62. }
  63. readonly connector: IDataConnector<ReadonlyJSONValue> | null;
  64. readonly id: string;
  65. get mode(): IDebugger.Mode {
  66. return this._mode;
  67. }
  68. set mode(mode: IDebugger.Mode) {
  69. if (this._mode === mode) {
  70. return;
  71. }
  72. this._mode = mode;
  73. this._modeChanged.emit(mode);
  74. }
  75. get sidebar() {
  76. return this._sidebar;
  77. }
  78. set sidebar(sidebar: DebuggerSidebar) {
  79. this._sidebar = sidebar;
  80. }
  81. get modeChanged(): ISignal<this, IDebugger.Mode> {
  82. return this._modeChanged;
  83. }
  84. get isDisposed(): boolean {
  85. return this._isDisposed;
  86. }
  87. get codeValue() {
  88. return this._codeValue;
  89. }
  90. set codeValue(observableString: IObservableString) {
  91. this._codeValue = observableString;
  92. }
  93. get currentLineChanged() {
  94. return this._currentLineChanged;
  95. }
  96. dispose(): void {
  97. this._isDisposed = true;
  98. }
  99. private async _populate(): Promise<void> {
  100. const { connector } = this;
  101. if (!connector) {
  102. return;
  103. }
  104. }
  105. private _codeValue: IObservableString;
  106. private _sidebar: DebuggerSidebar;
  107. private _isDisposed = false;
  108. private _mode: IDebugger.Mode;
  109. private _modeChanged = new Signal<this, IDebugger.Mode>(this);
  110. private _currentLineChanged = new Signal<this, number>(this);
  111. }
  112. export namespace Model {
  113. export interface IOptions extends Debugger.IOptions {}
  114. }
  115. }