tokens.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { IClientSession } from '@jupyterlab/apputils';
  4. import { Session } from '@jupyterlab/services';
  5. import { Token } from '@phosphor/coreutils';
  6. import { IDisposable, IObservableDisposable } from '@phosphor/disposable';
  7. import { ISignal } from '@phosphor/signaling';
  8. import { DebugProtocol } from 'vscode-debugprotocol';
  9. // TODO: remove that import when an interface has
  10. // been created for Model class
  11. import { Breakpoints } from './breakpoints';
  12. import { Debugger } from './debugger';
  13. /**
  14. * An interface describing an application's visual debugger.
  15. */
  16. export interface IDebugger extends IDisposable {
  17. /**
  18. * The mode of the debugger UI.
  19. *
  20. * #### Notes
  21. * There is only ever one debugger instance. If it is `expanded`, it exists
  22. * as a `MainAreaWidget`, otherwise it is a sidebar.
  23. */
  24. mode: IDebugger.Mode;
  25. /**
  26. * The current debugger session.
  27. */
  28. session: IDebugger.ISession;
  29. /**
  30. * The model of the debugger.
  31. */
  32. model: Debugger.Model;
  33. /**
  34. * Signal emitted upon session changed.
  35. */
  36. readonly sessionChanged: ISignal<IDebugger, IDebugger.ISession>;
  37. /**
  38. * Signal emitted upon model changed.
  39. */
  40. readonly modelChanged: ISignal<IDebugger, Debugger.Model>;
  41. /**
  42. * Signal emitted for debug event messages.
  43. */
  44. readonly eventMessage: ISignal<IDebugger, IDebugger.ISession.Event>;
  45. /**
  46. * Whether the current debugger is started.
  47. */
  48. isStarted(): boolean;
  49. /**
  50. * Whether the current thread is stopped.
  51. */
  52. isThreadStopped(): boolean;
  53. /**
  54. * Starts a debugger.
  55. * Precondition: canStart() && !isStarted()
  56. */
  57. start(): Promise<void>;
  58. /**
  59. * Stops the debugger.
  60. * Precondition: isStarted()
  61. */
  62. stop(): Promise<void>;
  63. /**
  64. * Restart the debugger.
  65. * Precondition: isStarted()
  66. */
  67. restart(): Promise<void>;
  68. /**
  69. * Restore the state of a debug session.
  70. * @param autoStart - when true, starts the debugger
  71. * if it has not been started yet.
  72. */
  73. restoreState(autoStart: boolean): Promise<void>;
  74. /**
  75. * Continues the execution of the current thread.
  76. */
  77. continue(): Promise<void>;
  78. /**
  79. * Makes the current thread run again for one step.
  80. */
  81. next(): Promise<void>;
  82. /**
  83. * Makes the current thread step in a function / method if possible.
  84. */
  85. stepIn(): Promise<void>;
  86. /**
  87. * Makes the current thread step out a function / method if possible.
  88. */
  89. stepOut(): Promise<void>;
  90. /**
  91. * Update all breakpoints at once.
  92. */
  93. updateBreakpoints(breakpoints: Breakpoints.IBreakpoint[]): Promise<void>;
  94. }
  95. /**
  96. * A namespace for visual debugger types.
  97. */
  98. export namespace IDebugger {
  99. /**
  100. * The mode of the debugger UI.
  101. */
  102. export type Mode = 'condensed' | 'expanded';
  103. /**
  104. * A visual debugger session.
  105. */
  106. export interface ISession extends IObservableDisposable {
  107. /**
  108. * The API client session to connect to a debugger.
  109. */
  110. client: IClientSession | Session.ISession;
  111. /**
  112. * Whether the debug session is started
  113. */
  114. readonly isStarted: boolean;
  115. /**
  116. * Signal emitted for debug event messages.
  117. */
  118. readonly eventMessage: ISignal<
  119. IDebugger.ISession,
  120. IDebugger.ISession.Event
  121. >;
  122. /**
  123. * Start a new debug session.
  124. */
  125. start(): Promise<void>;
  126. /**
  127. * Stop a running debug session.
  128. */
  129. stop(): Promise<void>;
  130. /**
  131. * Restore the state of a debug session.
  132. */
  133. restoreState(): Promise<IDebugger.ISession.Response['debugInfo']>;
  134. /**
  135. * Send a debug request to the kernel.
  136. */
  137. sendRequest<K extends keyof IDebugger.ISession.Request>(
  138. command: K,
  139. args: IDebugger.ISession.Request[K]
  140. ): Promise<IDebugger.ISession.Response[K]>;
  141. }
  142. export namespace ISession {
  143. /**
  144. * Arguments for 'dumpCell' request.
  145. * This is an addition to the Debug Adapter Protocol to support
  146. * setting breakpoints for cells.
  147. */
  148. export interface IDumpCellArguments {
  149. code: string;
  150. }
  151. /**
  152. * Response to 'dumpCell' request.
  153. * This is an addition to the Debug Adapter Protocol to support
  154. * setting breakpoints for cells.
  155. */
  156. export interface IDumpCellResponse extends DebugProtocol.Response {
  157. body: {
  158. sourcePath: string;
  159. };
  160. }
  161. /**
  162. * List of breakpoints in a source file.
  163. */
  164. export interface IDebugInfoBreakpoints {
  165. source: string;
  166. lines: number[];
  167. }
  168. /**
  169. * Response to 'debugInfo' request.
  170. * This is an addition to the Debug Adapter Protocol to be able
  171. * to retrieve the debugger state when restoring a session.
  172. */
  173. export interface IDebugInfoResponse extends DebugProtocol.Response {
  174. body: {
  175. isStarted: boolean;
  176. hashMethod: string;
  177. hashSeed: number;
  178. breakpoints: IDebugInfoBreakpoints[];
  179. };
  180. }
  181. /**
  182. * Expose all the debug requests types.
  183. */
  184. export type Request = {
  185. attach: DebugProtocol.AttachRequestArguments;
  186. completions: DebugProtocol.CompletionsArguments;
  187. configurationDone: DebugProtocol.ConfigurationDoneArguments;
  188. continue: DebugProtocol.ContinueArguments;
  189. debugInfo: {};
  190. disconnect: DebugProtocol.DisconnectArguments;
  191. dumpCell: IDumpCellArguments;
  192. evaluate: DebugProtocol.EvaluateArguments;
  193. exceptionInfo: DebugProtocol.ExceptionInfoArguments;
  194. goto: DebugProtocol.GotoArguments;
  195. gotoTargets: DebugProtocol.GotoTargetsArguments;
  196. initialize: DebugProtocol.InitializeRequestArguments;
  197. launch: DebugProtocol.LaunchRequestArguments;
  198. loadedSources: DebugProtocol.LoadedSourcesArguments;
  199. modules: DebugProtocol.ModulesArguments;
  200. next: DebugProtocol.NextArguments;
  201. pause: DebugProtocol.PauseArguments;
  202. restart: DebugProtocol.RestartArguments;
  203. restartFrame: DebugProtocol.RestartFrameArguments;
  204. reverseContinue: DebugProtocol.ReverseContinueArguments;
  205. scopes: DebugProtocol.ScopesArguments;
  206. setBreakpoints: DebugProtocol.SetBreakpointsArguments;
  207. setExceptionBreakpoints: DebugProtocol.SetExceptionBreakpointsArguments;
  208. setExpression: DebugProtocol.SetExpressionArguments;
  209. setFunctionBreakpoints: DebugProtocol.SetFunctionBreakpointsArguments;
  210. setVariable: DebugProtocol.SetVariableArguments;
  211. source: DebugProtocol.SourceArguments;
  212. stackTrace: DebugProtocol.StackTraceArguments;
  213. stepBack: DebugProtocol.StepBackArguments;
  214. stepIn: DebugProtocol.StepInArguments;
  215. stepInTargets: DebugProtocol.StepInTargetsArguments;
  216. stepOut: DebugProtocol.StepOutArguments;
  217. terminate: DebugProtocol.TerminateArguments;
  218. terminateThreads: DebugProtocol.TerminateThreadsArguments;
  219. threads: {};
  220. variables: DebugProtocol.VariablesArguments;
  221. };
  222. /**
  223. * Expose all the debug response types.
  224. */
  225. export type Response = {
  226. attach: DebugProtocol.AttachResponse;
  227. completions: DebugProtocol.CompletionsResponse;
  228. configurationDone: DebugProtocol.ConfigurationDoneResponse;
  229. continue: DebugProtocol.ContinueResponse;
  230. debugInfo: IDebugInfoResponse;
  231. disconnect: DebugProtocol.DisconnectResponse;
  232. dumpCell: IDumpCellResponse;
  233. evaluate: DebugProtocol.EvaluateResponse;
  234. exceptionInfo: DebugProtocol.ExceptionInfoResponse;
  235. goto: DebugProtocol.GotoResponse;
  236. gotoTargets: DebugProtocol.GotoTargetsResponse;
  237. initialize: DebugProtocol.InitializeResponse;
  238. launch: DebugProtocol.LaunchResponse;
  239. loadedSources: DebugProtocol.LoadedSourcesResponse;
  240. modules: DebugProtocol.ModulesResponse;
  241. next: DebugProtocol.NextResponse;
  242. pause: DebugProtocol.PauseResponse;
  243. restart: DebugProtocol.RestartResponse;
  244. restartFrame: DebugProtocol.RestartFrameResponse;
  245. reverseContinue: DebugProtocol.ReverseContinueResponse;
  246. scopes: DebugProtocol.ScopesResponse;
  247. setBreakpoints: DebugProtocol.SetBreakpointsResponse;
  248. setExceptionBreakpoints: DebugProtocol.SetExceptionBreakpointsResponse;
  249. setExpression: DebugProtocol.SetExpressionResponse;
  250. setFunctionBreakpoints: DebugProtocol.SetFunctionBreakpointsResponse;
  251. setVariable: DebugProtocol.SetVariableResponse;
  252. source: DebugProtocol.SourceResponse;
  253. stackTrace: DebugProtocol.StackTraceResponse;
  254. stepBack: DebugProtocol.StepBackResponse;
  255. stepIn: DebugProtocol.StepInResponse;
  256. stepInTargets: DebugProtocol.StepInTargetsResponse;
  257. stepOut: DebugProtocol.StepOutResponse;
  258. terminate: DebugProtocol.TerminateResponse;
  259. terminateThreads: DebugProtocol.TerminateThreadsResponse;
  260. threads: DebugProtocol.ThreadsResponse;
  261. variables: DebugProtocol.VariablesResponse;
  262. };
  263. /**
  264. * A generic debug event.
  265. */
  266. export type Event = DebugProtocol.Event;
  267. }
  268. }
  269. /**
  270. * A token for a tracker for an application's visual debugger instances.
  271. */
  272. export const IDebugger = new Token<IDebugger>('@jupyterlab/debugger');