Skip to content

Commit 448d14e

Browse files
authored
Make breakpoint data available in EH immediately, not after a call to debug API (microsoft#186796)
Fix microsoft#169699
1 parent f2386a5 commit 448d14e

File tree

4 files changed

+46
-64
lines changed

4 files changed

+46
-64
lines changed

extensions/vscode-api-tests/src/singlefolder-tests/debug.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@
66
import * as assert from 'assert';
77
import { basename } from 'path';
88
import { commands, debug, Disposable, window, workspace } from 'vscode';
9-
import { assertNoRpc, disposeAll } from '../utils';
9+
import { assertNoRpc, createRandomFile, disposeAll } from '../utils';
1010

1111
suite('vscode API - debug', function () {
1212

1313
teardown(assertNoRpc);
1414

15+
test('breakpoints are available before accessing debug extension API', async () => {
16+
const file = await createRandomFile(undefined, undefined, '.js');
17+
const doc = await workspace.openTextDocument(file);
18+
await window.showTextDocument(doc);
19+
await commands.executeCommand('editor.debug.action.toggleBreakpoint');
20+
21+
assert.strictEqual(debug.breakpoints.length, 1);
22+
await commands.executeCommand('editor.debug.action.toggleBreakpoint');
23+
});
24+
1525
test('breakpoints', async function () {
1626
assert.strictEqual(debug.breakpoints.length, 0);
1727
let onDidChangeBreakpointsCounter = 0;

src/vs/workbench/api/browser/mainThreadDebugService.ts

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
2222

2323
private readonly _proxy: ExtHostDebugServiceShape;
2424
private readonly _toDispose = new DisposableStore();
25-
private _breakpointEventsActive: boolean | undefined;
2625
private readonly _debugAdapters: Map<number, ExtensionHostDebugAdapter>;
2726
private _debugAdaptersHandleCounter = 1;
2827
private readonly _debugConfigurationProviders: Map<number, IDebugConfigurationProvider>;
@@ -79,6 +78,40 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
7978
this._proxy.$acceptStackFrameFocus(dto);
8079
}
8180
}));
81+
this.sendBreakpointsAndListen();
82+
}
83+
84+
private sendBreakpointsAndListen(): void {
85+
// set up a handler to send more
86+
this._toDispose.add(this.debugService.getModel().onDidChangeBreakpoints(e => {
87+
// Ignore session only breakpoint events since they should only reflect in the UI
88+
if (e && !e.sessionOnly) {
89+
const delta: IBreakpointsDeltaDto = {};
90+
if (e.added) {
91+
delta.added = this.convertToDto(e.added);
92+
}
93+
if (e.removed) {
94+
delta.removed = e.removed.map(x => x.getId());
95+
}
96+
if (e.changed) {
97+
delta.changed = this.convertToDto(e.changed);
98+
}
99+
100+
if (delta.added || delta.removed || delta.changed) {
101+
this._proxy.$acceptBreakpointsDelta(delta);
102+
}
103+
}
104+
}));
105+
106+
// send all breakpoints
107+
const bps = this.debugService.getModel().getBreakpoints();
108+
const fbps = this.debugService.getModel().getFunctionBreakpoints();
109+
const dbps = this.debugService.getModel().getDataBreakpoints();
110+
if (bps.length > 0 || fbps.length > 0) {
111+
this._proxy.$acceptBreakpointsDelta({
112+
added: this.convertToDto(bps).concat(this.convertToDto(fbps)).concat(this.convertToDto(dbps))
113+
});
114+
}
82115
}
83116

84117
public dispose(): void {
@@ -108,44 +141,6 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb
108141
this._toDispose.add(this.debugService.getAdapterManager().registerDebugAdapterFactory(debugTypes, this));
109142
}
110143

111-
public $startBreakpointEvents(): void {
112-
113-
if (!this._breakpointEventsActive) {
114-
this._breakpointEventsActive = true;
115-
116-
// set up a handler to send more
117-
this._toDispose.add(this.debugService.getModel().onDidChangeBreakpoints(e => {
118-
// Ignore session only breakpoint events since they should only reflect in the UI
119-
if (e && !e.sessionOnly) {
120-
const delta: IBreakpointsDeltaDto = {};
121-
if (e.added) {
122-
delta.added = this.convertToDto(e.added);
123-
}
124-
if (e.removed) {
125-
delta.removed = e.removed.map(x => x.getId());
126-
}
127-
if (e.changed) {
128-
delta.changed = this.convertToDto(e.changed);
129-
}
130-
131-
if (delta.added || delta.removed || delta.changed) {
132-
this._proxy.$acceptBreakpointsDelta(delta);
133-
}
134-
}
135-
}));
136-
137-
// send all breakpoints
138-
const bps = this.debugService.getModel().getBreakpoints();
139-
const fbps = this.debugService.getModel().getFunctionBreakpoints();
140-
const dbps = this.debugService.getModel().getDataBreakpoints();
141-
if (bps.length > 0 || fbps.length > 0) {
142-
this._proxy.$acceptBreakpointsDelta({
143-
added: this.convertToDto(bps).concat(this.convertToDto(fbps)).concat(this.convertToDto(dbps))
144-
});
145-
}
146-
}
147-
}
148-
149144
public $registerBreakpoints(DTOs: Array<ISourceMultiBreakpointDto | IFunctionBreakpointDto | IDataBreakpointDto>): Promise<void> {
150145

151146
for (const dto of DTOs) {

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,6 @@ export interface MainThreadDebugServiceShape extends IDisposable {
14041404
$customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): Promise<any>;
14051405
$getDebugProtocolBreakpoint(id: DebugSessionUUID, breakpoinId: string): Promise<DebugProtocol.Breakpoint | undefined>;
14061406
$appendDebugConsole(value: string): void;
1407-
$startBreakpointEvents(): void;
14081407
$registerBreakpoints(breakpoints: Array<ISourceMultiBreakpointDto | IFunctionBreakpointDto | IDataBreakpointDto>): Promise<void>;
14091408
$unregisterBreakpoints(breakpointIds: string[], functionBreakpointIds: string[], dataBreakpointIds: string[]): Promise<void>;
14101409
}

src/vs/workbench/api/common/extHostDebugService.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
8989
get activeDebugConsole(): vscode.DebugConsole { return this._activeDebugConsole.value; }
9090

9191
private _breakpoints: Map<string, vscode.Breakpoint>;
92-
private _breakpointEventsActive: boolean;
9392

9493
private readonly _onDidChangeBreakpoints: Emitter<vscode.BreakpointsChangeEvent>;
9594

@@ -128,18 +127,13 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
128127

129128
this._debugServiceProxy = extHostRpcService.getProxy(MainContext.MainThreadDebugService);
130129

131-
this._onDidChangeBreakpoints = new Emitter<vscode.BreakpointsChangeEvent>({
132-
onWillAddFirstListener: () => {
133-
this.startBreakpoints();
134-
}
135-
});
130+
this._onDidChangeBreakpoints = new Emitter<vscode.BreakpointsChangeEvent>();
136131

137132
this._onDidChangeStackFrameFocus = new Emitter<vscode.ThreadFocus | vscode.StackFrameFocus | undefined>();
138133

139134
this._activeDebugConsole = new ExtHostDebugConsole(this._debugServiceProxy);
140135

141136
this._breakpoints = new Map<string, vscode.Breakpoint>();
142-
this._breakpointEventsActive = false;
143137

144138
this._extensionService.getExtensionRegistry().then((extensionRegistry: ExtensionDescriptionRegistry) => {
145139
extensionRegistry.onDidChange(_ => {
@@ -211,18 +205,12 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
211205
}
212206

213207
get breakpoints(): vscode.Breakpoint[] {
214-
215-
this.startBreakpoints();
216-
217208
const result: vscode.Breakpoint[] = [];
218209
this._breakpoints.forEach(bp => result.push(bp));
219210
return result;
220211
}
221212

222213
public addBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void> {
223-
224-
this.startBreakpoints();
225-
226214
// filter only new breakpoints
227215
const breakpoints = breakpoints0.filter(bp => {
228216
const id = bp.id;
@@ -278,9 +266,6 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
278266
}
279267

280268
public removeBreakpoints(breakpoints0: vscode.Breakpoint[]): Promise<void> {
281-
282-
this.startBreakpoints();
283-
284269
// remove from array
285270
const breakpoints = breakpoints0.filter(b => this._breakpoints.delete(b.id));
286271

@@ -835,13 +820,6 @@ export abstract class ExtHostDebugServiceBase implements IExtHostDebugService, E
835820
return undefined;
836821
}
837822

838-
private startBreakpoints() {
839-
if (!this._breakpointEventsActive) {
840-
this._breakpointEventsActive = true;
841-
this._debugServiceProxy.$startBreakpointEvents();
842-
}
843-
}
844-
845823
private fireBreakpointChanges(added: vscode.Breakpoint[], removed: vscode.Breakpoint[], changed: vscode.Breakpoint[]) {
846824
if (added.length > 0 || removed.length > 0 || changed.length > 0) {
847825
this._onDidChangeBreakpoints.fire(Object.freeze({

0 commit comments

Comments
 (0)