forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplexingDebugService.ts
More file actions
188 lines (177 loc) · 8.14 KB
/
multiplexingDebugService.ts
File metadata and controls
188 lines (177 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { inject, injectable, named } from 'inversify';
import {
Breakpoint,
BreakpointsChangeEvent,
DebugAdapterDescriptorFactory,
DebugAdapterTrackerFactory,
DebugConfiguration,
DebugConfigurationProvider,
DebugConsole,
DebugSession,
DebugSessionCustomEvent,
Disposable,
Event,
EventEmitter,
WorkspaceFolder
} from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { ICommandManager, IDebugService } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { Identifiers } from './constants';
import { IJupyterDebugService } from './types';
/**
* IJupyterDebugService that will pick the correct debugger based on if doing run by line or normal debugging.
* RunByLine will use the JupyterDebugService, Normal debugging will use the VS code debug service.
*/
@injectable()
export class MultiplexingDebugService implements IJupyterDebugService {
private lastStartedService: IDebugService | undefined;
private sessionChangedEvent: EventEmitter<DebugSession | undefined> = new EventEmitter<DebugSession | undefined>();
private sessionStartedEvent: EventEmitter<DebugSession> = new EventEmitter<DebugSession>();
private sessionTerminatedEvent: EventEmitter<DebugSession> = new EventEmitter<DebugSession>();
private sessionCustomEvent: EventEmitter<DebugSessionCustomEvent> = new EventEmitter<DebugSessionCustomEvent>();
constructor(
@inject(IDisposableRegistry) disposableRegistry: IDisposableRegistry,
@inject(ICommandManager) private commandManager: ICommandManager,
@inject(IDebugService) private vscodeDebugService: IDebugService,
@inject(IJupyterDebugService)
@named(Identifiers.RUN_BY_LINE_DEBUGSERVICE)
private jupyterDebugService: IJupyterDebugService
) {
disposableRegistry.push(vscodeDebugService.onDidTerminateDebugSession(this.endedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidTerminateDebugSession(this.endedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidStartDebugSession(this.startedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidStartDebugSession(this.startedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidChangeActiveDebugSession(this.changedDebugSession.bind(this)));
disposableRegistry.push(jupyterDebugService.onDidChangeActiveDebugSession(this.changedDebugSession.bind(this)));
disposableRegistry.push(vscodeDebugService.onDidReceiveDebugSessionCustomEvent(this.gotCustomEvent.bind(this)));
disposableRegistry.push(
jupyterDebugService.onDidReceiveDebugSessionCustomEvent(this.gotCustomEvent.bind(this))
);
}
public get activeDebugSession(): DebugSession | undefined {
return this.activeService.activeDebugSession;
}
public get activeDebugConsole(): DebugConsole {
return this.activeService.activeDebugConsole;
}
public get breakpoints(): Breakpoint[] {
return this.activeService.breakpoints;
}
public get onDidChangeActiveDebugSession(): Event<DebugSession | undefined> {
return this.sessionChangedEvent.event;
}
public get onDidStartDebugSession(): Event<DebugSession> {
return this.sessionStartedEvent.event;
}
public get onDidReceiveDebugSessionCustomEvent(): Event<DebugSessionCustomEvent> {
return this.sessionCustomEvent.event;
}
public get onDidTerminateDebugSession(): Event<DebugSession> {
return this.sessionTerminatedEvent.event;
}
public get onDidChangeBreakpoints(): Event<BreakpointsChangeEvent> {
return this.activeService.onDidChangeBreakpoints;
}
public get onBreakpointHit(): Event<void> {
return this.jupyterDebugService.onBreakpointHit;
}
public startRunByLine(config: DebugConfiguration): Thenable<boolean> {
this.lastStartedService = this.jupyterDebugService;
return this.jupyterDebugService.startRunByLine(config);
}
public registerDebugConfigurationProvider(debugType: string, provider: DebugConfigurationProvider): Disposable {
const d1 = this.vscodeDebugService.registerDebugConfigurationProvider(debugType, provider);
const d2 = this.jupyterDebugService.registerDebugConfigurationProvider(debugType, provider);
return this.combineDisposables(d1, d2);
}
public registerDebugAdapterDescriptorFactory(
debugType: string,
factory: DebugAdapterDescriptorFactory
): Disposable {
const d1 = this.vscodeDebugService.registerDebugAdapterDescriptorFactory(debugType, factory);
const d2 = this.jupyterDebugService.registerDebugAdapterDescriptorFactory(debugType, factory);
return this.combineDisposables(d1, d2);
}
public registerDebugAdapterTrackerFactory(debugType: string, factory: DebugAdapterTrackerFactory): Disposable {
const d1 = this.vscodeDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
const d2 = this.jupyterDebugService.registerDebugAdapterTrackerFactory(debugType, factory);
return this.combineDisposables(d1, d2);
}
public startDebugging(
folder: WorkspaceFolder | undefined,
nameOrConfiguration: string | DebugConfiguration,
parentSession?: DebugSession | undefined
): Thenable<boolean> {
this.lastStartedService = this.vscodeDebugService;
return this.vscodeDebugService.startDebugging(folder, nameOrConfiguration, parentSession);
}
public addBreakpoints(breakpoints: Breakpoint[]): void {
return this.activeService.addBreakpoints(breakpoints);
}
public removeBreakpoints(breakpoints: Breakpoint[]): void {
return this.activeService.removeBreakpoints(breakpoints);
}
public getStack(): Promise<DebugProtocol.StackFrame[]> {
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.getStack();
}
throw new Error('Requesting jupyter specific stack when not debugging.');
}
public step(): Promise<void> {
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.step();
}
throw new Error('Requesting jupyter specific step when not debugging.');
}
public continue(): Promise<void> {
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.continue();
}
throw new Error('Requesting jupyter specific step when not debugging.');
}
public requestVariables(): Promise<void> {
if (this.lastStartedService === this.jupyterDebugService) {
return this.jupyterDebugService.requestVariables();
}
throw new Error('Requesting jupyter specific variables when not debugging.');
}
public stop(): void {
if (this.lastStartedService === this.jupyterDebugService) {
this.jupyterDebugService.stop();
} else {
// Stop our debugging UI session, no await as we just want it stopped
this.commandManager.executeCommand('workbench.action.debug.stop');
}
}
private get activeService(): IDebugService {
if (this.lastStartedService) {
return this.lastStartedService;
} else {
return this.vscodeDebugService;
}
}
private combineDisposables(d1: Disposable, d2: Disposable): Disposable {
return {
dispose: () => {
d1.dispose();
d2.dispose();
}
};
}
private endedDebugSession(session: DebugSession) {
this.sessionTerminatedEvent.fire(session);
this.lastStartedService = undefined;
}
private startedDebugSession(session: DebugSession) {
this.sessionStartedEvent.fire(session);
}
private changedDebugSession(session: DebugSession | undefined) {
this.sessionChangedEvent.fire(session);
}
private gotCustomEvent(e: DebugSessionCustomEvent) {
this.sessionCustomEvent.fire(e);
}
}