tokens.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. * Computes an id based on the given code.
  47. */
  48. getCellId(code: string): string;
  49. /**
  50. * Whether the current debugger is started.
  51. */
  52. isStarted(): boolean;
  53. /**
  54. * Whether the current thread is stopped.
  55. */
  56. isThreadStopped(): boolean;
  57. /**
  58. * Starts a debugger.
  59. * Precondition: canStart() && !isStarted()
  60. */
  61. start(): Promise<void>;
  62. /**
  63. * Stops the debugger.
  64. * Precondition: isStarted()
  65. */
  66. stop(): Promise<void>;
  67. /**
  68. * Restart the debugger.
  69. * Precondition: isStarted()
  70. */
  71. restart(): Promise<void>;
  72. /**
  73. * Restore the state of a debug session.
  74. * @param autoStart - when true, starts the debugger
  75. * if it has not been started yet.
  76. */
  77. restoreState(autoStart: boolean): Promise<void>;
  78. /**
  79. * Continues the execution of the current thread.
  80. */
  81. continue(): Promise<void>;
  82. /**
  83. * Makes the current thread run again for one step.
  84. */
  85. next(): Promise<void>;
  86. /**
  87. * Makes the current thread step in a function / method if possible.
  88. */
  89. stepIn(): Promise<void>;
  90. /**
  91. * Makes the current thread step out a function / method if possible.
  92. */
  93. stepOut(): Promise<void>;
  94. /**
  95. * Update all breakpoints of a cell at once.
  96. * @param code - The code in the cell where the breakpoints are set.
  97. * @param breakpoints - The list of breakpoints to set.
  98. */
  99. updateBreakpoints(
  100. code: string,
  101. breakpoints: Breakpoints.IBreakpoint[]
  102. ): Promise<void>;
  103. /**
  104. * Removes all the breakpoints from the current notebook or console
  105. */
  106. clearBreakpoints(): Promise<void>;
  107. }
  108. /**
  109. * A namespace for visual debugger types.
  110. */
  111. export namespace IDebugger {
  112. /**
  113. * The mode of the debugger UI.
  114. */
  115. export type Mode = 'condensed' | 'expanded';
  116. /**
  117. * A visual debugger session.
  118. */
  119. export interface ISession extends IObservableDisposable {
  120. /**
  121. * The API client session to connect to a debugger.
  122. */
  123. client: IClientSession | Session.ISession;
  124. /**
  125. * Whether the debug session is started
  126. */
  127. readonly isStarted: boolean;
  128. /**
  129. * Signal emitted for debug event messages.
  130. */
  131. readonly eventMessage: ISignal<
  132. IDebugger.ISession,
  133. IDebugger.ISession.Event
  134. >;
  135. /**
  136. * Start a new debug session.
  137. */
  138. start(): Promise<void>;
  139. /**
  140. * Stop a running debug session.
  141. */
  142. stop(): Promise<void>;
  143. /**
  144. * Restore the state of a debug session.
  145. */
  146. restoreState(): Promise<IDebugger.ISession.Response['debugInfo']>;
  147. /**
  148. * Send a debug request to the kernel.
  149. */
  150. sendRequest<K extends keyof IDebugger.ISession.Request>(
  151. command: K,
  152. args: IDebugger.ISession.Request[K]
  153. ): Promise<IDebugger.ISession.Response[K]>;
  154. }
  155. export namespace ISession {
  156. /**
  157. * Arguments for 'dumpCell' request.
  158. * This is an addition to the Debug Adapter Protocol to support
  159. * setting breakpoints for cells.
  160. */
  161. export interface IDumpCellArguments {
  162. code: string;
  163. }
  164. /**
  165. * Response to 'dumpCell' request.
  166. * This is an addition to the Debug Adapter Protocol to support
  167. * setting breakpoints for cells.
  168. */
  169. export interface IDumpCellResponse extends DebugProtocol.Response {
  170. body: {
  171. sourcePath: string;
  172. };
  173. }
  174. /**
  175. * List of breakpoints in a source file.
  176. */
  177. export interface IDebugInfoBreakpoints {
  178. source: string;
  179. breakpoints: DebugProtocol.Breakpoint[];
  180. }
  181. /**
  182. * Response to 'debugInfo' request.
  183. * This is an addition to the Debug Adapter Protocol to be able
  184. * to retrieve the debugger state when restoring a session.
  185. */
  186. export interface IDebugInfoResponse extends DebugProtocol.Response {
  187. body: {
  188. isStarted: boolean;
  189. hashMethod: string;
  190. hashSeed: number;
  191. breakpoints: IDebugInfoBreakpoints[];
  192. tmpFilePrefix: string;
  193. tmpFileSuffix: string;
  194. stoppedThreads: number[];
  195. };
  196. }
  197. /**
  198. * Expose all the debug requests types.
  199. */
  200. export type Request = {
  201. attach: DebugProtocol.AttachRequestArguments;
  202. completions: DebugProtocol.CompletionsArguments;
  203. configurationDone: DebugProtocol.ConfigurationDoneArguments;
  204. continue: DebugProtocol.ContinueArguments;
  205. debugInfo: {};
  206. disconnect: DebugProtocol.DisconnectArguments;
  207. dumpCell: IDumpCellArguments;
  208. evaluate: DebugProtocol.EvaluateArguments;
  209. exceptionInfo: DebugProtocol.ExceptionInfoArguments;
  210. goto: DebugProtocol.GotoArguments;
  211. gotoTargets: DebugProtocol.GotoTargetsArguments;
  212. initialize: DebugProtocol.InitializeRequestArguments;
  213. launch: DebugProtocol.LaunchRequestArguments;
  214. loadedSources: DebugProtocol.LoadedSourcesArguments;
  215. modules: DebugProtocol.ModulesArguments;
  216. next: DebugProtocol.NextArguments;
  217. pause: DebugProtocol.PauseArguments;
  218. restart: DebugProtocol.RestartArguments;
  219. restartFrame: DebugProtocol.RestartFrameArguments;
  220. reverseContinue: DebugProtocol.ReverseContinueArguments;
  221. scopes: DebugProtocol.ScopesArguments;
  222. setBreakpoints: DebugProtocol.SetBreakpointsArguments;
  223. setExceptionBreakpoints: DebugProtocol.SetExceptionBreakpointsArguments;
  224. setExpression: DebugProtocol.SetExpressionArguments;
  225. setFunctionBreakpoints: DebugProtocol.SetFunctionBreakpointsArguments;
  226. setVariable: DebugProtocol.SetVariableArguments;
  227. source: DebugProtocol.SourceArguments;
  228. stackTrace: DebugProtocol.StackTraceArguments;
  229. stepBack: DebugProtocol.StepBackArguments;
  230. stepIn: DebugProtocol.StepInArguments;
  231. stepInTargets: DebugProtocol.StepInTargetsArguments;
  232. stepOut: DebugProtocol.StepOutArguments;
  233. terminate: DebugProtocol.TerminateArguments;
  234. terminateThreads: DebugProtocol.TerminateThreadsArguments;
  235. threads: {};
  236. variables: DebugProtocol.VariablesArguments;
  237. };
  238. /**
  239. * Expose all the debug response types.
  240. */
  241. export type Response = {
  242. attach: DebugProtocol.AttachResponse;
  243. completions: DebugProtocol.CompletionsResponse;
  244. configurationDone: DebugProtocol.ConfigurationDoneResponse;
  245. continue: DebugProtocol.ContinueResponse;
  246. debugInfo: IDebugInfoResponse;
  247. disconnect: DebugProtocol.DisconnectResponse;
  248. dumpCell: IDumpCellResponse;
  249. evaluate: DebugProtocol.EvaluateResponse;
  250. exceptionInfo: DebugProtocol.ExceptionInfoResponse;
  251. goto: DebugProtocol.GotoResponse;
  252. gotoTargets: DebugProtocol.GotoTargetsResponse;
  253. initialize: DebugProtocol.InitializeResponse;
  254. launch: DebugProtocol.LaunchResponse;
  255. loadedSources: DebugProtocol.LoadedSourcesResponse;
  256. modules: DebugProtocol.ModulesResponse;
  257. next: DebugProtocol.NextResponse;
  258. pause: DebugProtocol.PauseResponse;
  259. restart: DebugProtocol.RestartResponse;
  260. restartFrame: DebugProtocol.RestartFrameResponse;
  261. reverseContinue: DebugProtocol.ReverseContinueResponse;
  262. scopes: DebugProtocol.ScopesResponse;
  263. setBreakpoints: DebugProtocol.SetBreakpointsResponse;
  264. setExceptionBreakpoints: DebugProtocol.SetExceptionBreakpointsResponse;
  265. setExpression: DebugProtocol.SetExpressionResponse;
  266. setFunctionBreakpoints: DebugProtocol.SetFunctionBreakpointsResponse;
  267. setVariable: DebugProtocol.SetVariableResponse;
  268. source: DebugProtocol.SourceResponse;
  269. stackTrace: DebugProtocol.StackTraceResponse;
  270. stepBack: DebugProtocol.StepBackResponse;
  271. stepIn: DebugProtocol.StepInResponse;
  272. stepInTargets: DebugProtocol.StepInTargetsResponse;
  273. stepOut: DebugProtocol.StepOutResponse;
  274. terminate: DebugProtocol.TerminateResponse;
  275. terminateThreads: DebugProtocol.TerminateThreadsResponse;
  276. threads: DebugProtocol.ThreadsResponse;
  277. variables: DebugProtocol.VariablesResponse;
  278. };
  279. /**
  280. * A generic debug event.
  281. */
  282. export type Event = DebugProtocol.Event;
  283. }
  284. }
  285. /**
  286. * A token for a tracker for an application's visual debugger instances.
  287. */
  288. export const IDebugger = new Token<IDebugger>('@jupyterlab/debugger');