From e2f8c3c4041ad93fe58989caaadd34062ae743cb Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Wed, 14 Nov 2018 15:38:45 +0100 Subject: [PATCH] Debug API: surface Breakpoint.id; for Microsoft/vscode#48722 --- src/vs/vscode.proposed.d.ts | 7 ++++ .../workbench/api/node/extHostDebugService.ts | 41 ++++++------------- src/vs/workbench/api/node/extHostTypes.ts | 10 +++++ 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 336eaa9204492..3d2c8e1ce0355 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -567,6 +567,13 @@ declare module 'vscode' { //#region André: debug + export interface Breakpoint { + /** + * The id of the breakpoint. + */ + readonly id: string; + } + /** * A debug session. */ diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index 25fc3a53d4f3b..c599abff14eb9 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -15,7 +15,6 @@ import { } from 'vs/workbench/api/node/extHost.protocol'; import * as vscode from 'vscode'; import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer, DebugAdapterExecutable, DebugAdapterImplementation } from 'vs/workbench/api/node/extHostTypes'; -import { generateUuid } from 'vs/base/common/uuid'; import { ExecutableDebugAdapter, SocketDebugAdapter, AbstractDebugAdapter } from 'vs/workbench/parts/debug/node/debugAdapter'; import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService'; @@ -157,23 +156,15 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { this.startBreakpoints(); - // assign uuids for brand new breakpoints - const breakpoints: vscode.Breakpoint[] = []; - for (const bp of breakpoints0) { - let id = bp['_id']; - if (id) { // has already id - if (this._breakpoints.has(id)) { - // already there - } else { - breakpoints.push(bp); - } - } else { - id = generateUuid(); - bp['_id'] = id; + // filter only new breakpoints + const breakpoints = breakpoints0.filter(bp => { + const id = bp.id; + if (!this._breakpoints.has(id)) { this._breakpoints.set(id, bp); - breakpoints.push(bp); + return true; } - } + return false; + }); // send notification for added breakpoints this.fireBreakpointChanges(breakpoints, [], []); @@ -194,7 +185,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { dtos.push(dto); } dto.lines.push({ - id: bp['_id'], + id: bp.id, enabled: bp.enabled, condition: bp.condition, hitCondition: bp.hitCondition, @@ -205,7 +196,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { } else if (bp instanceof FunctionBreakpoint) { dtos.push({ type: 'function', - id: bp['_id'], + id: bp.id, enabled: bp.enabled, hitCondition: bp.hitCondition, logMessage: bp.logMessage, @@ -224,20 +215,14 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { this.startBreakpoints(); // remove from array - const breakpoints: vscode.Breakpoint[] = []; - for (const b of breakpoints0) { - let id = b['_id']; - if (id && this._breakpoints.delete(id)) { - breakpoints.push(b); - } - } + const breakpoints = breakpoints0.filter(b => this._breakpoints.delete(b.id)); // send notification this.fireBreakpointChanges([], breakpoints, []); // unregister with VS Code - const ids = breakpoints.filter(bp => bp instanceof SourceBreakpoint).map(bp => bp['_id']); - const fids = breakpoints.filter(bp => bp instanceof FunctionBreakpoint).map(bp => bp['_id']); + const ids = breakpoints.filter(bp => bp instanceof SourceBreakpoint).map(bp => bp.id); + const fids = breakpoints.filter(bp => bp instanceof FunctionBreakpoint).map(bp => bp.id); return this._debugServiceProxy.$unregisterBreakpoints(ids, fids); } @@ -487,7 +472,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { const uri = URI.revive(bpd.uri); bp = new SourceBreakpoint(new Location(uri, new Position(bpd.line, bpd.character)), bpd.enabled, bpd.condition, bpd.hitCondition, bpd.logMessage); } - bp['_id'] = bpd.id; + (bp as any)._id = bpd.id; this._breakpoints.set(bpd.id, bp); a.push(bp); } diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 859bbfe80aa7e..f4d5445d03620 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -14,6 +14,7 @@ import { relative } from 'path'; import { startsWith } from 'vs/base/common/strings'; import { values } from 'vs/base/common/map'; import { coalesce, equals } from 'vs/base/common/arrays'; +import { generateUuid } from 'vs/base/common/uuid'; export class Disposable { @@ -1882,6 +1883,8 @@ export class RelativePattern implements IRelativePattern { export class Breakpoint { + private _id: string | undefined; + readonly enabled: boolean; readonly condition?: string; readonly hitCondition?: string; @@ -1899,6 +1902,13 @@ export class Breakpoint { this.logMessage = logMessage; } } + + get id(): string { + if (!this._id) { + this._id = generateUuid(); + } + return this._id; + } } export class SourceBreakpoint extends Breakpoint {