debugger.ts 4.4 KB

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