1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { DebugSession } from './session';
- import { IDebugger } from './tokens';
- import { DebugProtocol } from 'vscode-debugprotocol';
- import { Debugger } from './debugger';
- export class DebugService {
- constructor(session: DebugSession | null, debuggerModel: Debugger.Model) {
- this.session = session;
- this.model = debuggerModel;
- }
- private _session: DebugSession;
- // private _currentFrame: DebugProtocol.StackFrame;
- private _debuggerModel: Debugger.Model;
- set session(session: DebugSession) {
- this._session = session;
- }
- get session() {
- return this._session;
- }
- get model() {
- return this._debuggerModel;
- }
- set model(model: Debugger.Model) {
- this._debuggerModel = model;
- }
- // this will change for after execute cell
- async launch(code: string): Promise<void> {
- let threadId: number = 1;
- this.session.eventMessage.connect(
- (sender: DebugSession, event: IDebugger.ISession.Event) => {
- const eventName = event.event;
- if (eventName === 'thread') {
- const msg = event as DebugProtocol.ThreadEvent;
- threadId = msg.body.threadId;
- }
- }
- );
- const breakpoints: DebugProtocol.SourceBreakpoint[] = this.setBreakpoints();
- const reply = await this.session
- .sendRequest('dumpCell', {
- code
- })
- .catch(error => error);
- await this.session.sendRequest('setBreakpoints', {
- breakpoints: breakpoints,
- source: { path: reply.body.sourcePath },
- sourceModified: false
- });
- await this.session.sendRequest('configurationDone', {});
- this.session.client.kernel.requestExecute({ code });
- const stackFrameReply = await this.getFrames(threadId);
- const scopeReply = await this.getScopes(stackFrameReply);
- const variablesReply = await this.getVariables(scopeReply);
- console.log({ variablesReply, scopeReply, stackFrameReply });
- }
- getFrames = async (threadId: number) => {
- const reply = await this.session.sendRequest('stackTrace', {
- threadId
- });
- const stackFrames = reply.body.stackFrames;
- return stackFrames;
- };
- getScopes = async (frame: DebugProtocol.StackFrame[]) => {
- const reply = await this.session.sendRequest('scopes', {
- frameId: frame[0].id
- });
- return reply.body.scopes;
- };
- getVariables = async (scopes: DebugProtocol.Scope[]) => {
- const reply = await this.session.sendRequest('variables', {
- variablesReference: scopes[0].variablesReference
- });
- return reply.body.variables;
- };
- setBreakpoints = (): DebugProtocol.SourceBreakpoint[] => {
- return this.model.sidebar.breakpoints.model.breakpoints.map(breakpoint => {
- return {
- line: breakpoint.line
- };
- });
- };
- }
|