diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 073054ad61a..2994522a556 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -275,13 +275,13 @@ declare module 'vscode' { * Add breakpoints. * @param breakpoints The breakpoints to add. */ - export function addBreakpoints(breakpoints: Breakpoint[]): Thenable; + export function addBreakpoints(breakpoints: Breakpoint[]): void; /** * Remove breakpoints. * @param breakpoints The breakpoints to remove. */ - export function removeBreakpoints(breakpoints: Breakpoint[]): Thenable; + export function removeBreakpoints(breakpoints: Breakpoint[]): void; } /** diff --git a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts index 82c4bf07937..46140b8f54b 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDebugService.ts @@ -11,7 +11,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { ExtHostContext, ExtHostDebugServiceShape, MainThreadDebugServiceShape, DebugSessionUUID, MainContext, - IExtHostContext, IBreakpointsDeltaDto, ISourceMultiBreakpointDto, ISourceBreakpointDto, IFunctionBreakpointDto, IBreakpointIndexDto + IExtHostContext, IBreakpointsDeltaDto, ISourceMultiBreakpointDto, ISourceBreakpointDto, IFunctionBreakpointDto } from '../node/extHost.protocol'; import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import severity from 'vs/base/common/severity'; @@ -92,14 +92,13 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape { return TPromise.wrap(undefined); } - public async $registerBreakpoints(DTOs: (ISourceMultiBreakpointDto | IFunctionBreakpointDto)[]): TPromise { + public $registerBreakpoints(DTOs: (ISourceMultiBreakpointDto | IFunctionBreakpointDto)[]): TPromise { - const result: IBreakpointIndexDto[] = []; for (let dto of DTOs) { if (dto.type === 'sourceMulti') { - const sdto = dto; const rawbps = dto.lines.map(l => { + id: l.id, enabled: l.enabled, lineNumber: l.line + 1, column: l.character > 0 ? l.character + 1 : 0, @@ -107,20 +106,12 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape { hitCondition: l.hitCondition } ); - const bps = await this.debugService.addBreakpoints(uri.revive(dto.uri), rawbps); - bps.forEach((bp, ix) => result.push({ - index: sdto.lines[ix].index, - id: bp.getId() - })); + this.debugService.addBreakpoints(uri.revive(dto.uri), rawbps); } else if (dto.type === 'function') { - const fbs = this.debugService.addFunctionBreakpoint(dto.functionName); - result.push({ - index: dto.index, - id: fbs.getId() - }); + this.debugService.addFunctionBreakpoint(dto.functionName, dto.id); } } - return result; + return void 0; } public $unregisterBreakpoints(breakpointIds: string[], functionBreakpointIds: string[]): TPromise { diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index dd1bd6574d5..8d51f8782f5 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -443,7 +443,7 @@ export interface MainThreadDebugServiceShape extends IDisposable { $customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): TPromise; $appendDebugConsole(value: string): TPromise; $startBreakpointEvents(): TPromise; - $registerBreakpoints(breakpoints: (ISourceMultiBreakpointDto | IFunctionBreakpointDto)[]): TPromise; + $registerBreakpoints(breakpoints: (ISourceMultiBreakpointDto | IFunctionBreakpointDto)[]): TPromise; $unregisterBreakpoints(breakpointIds: string[], functionBreakpointIds: string[]): TPromise; } @@ -701,7 +701,6 @@ export interface ExtHostTaskShape { export interface IFunctionBreakpointDto { type: 'function'; - index: number; id?: string; enabled: boolean; condition?: string; @@ -730,7 +729,7 @@ export interface ISourceMultiBreakpointDto { type: 'sourceMulti'; uri: UriComponents; lines: { - index: number; + id: string; enabled: boolean; condition?: string; hitCondition?: string; @@ -739,11 +738,6 @@ export interface ISourceMultiBreakpointDto { }[]; } -export interface IBreakpointIndexDto { - index: number; - id: string; -} - export interface ExtHostDebugServiceShape { $resolveDebugConfiguration(handle: number, folder: UriComponents | undefined, debugConfiguration: IConfig): TPromise; $provideDebugConfigurations(handle: number, folder: UriComponents | undefined): TPromise; diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index feae87b4e7d..7b1cba6a42c 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -16,6 +16,7 @@ import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace'; import * as vscode from 'vscode'; import URI, { UriComponents } from 'vs/base/common/uri'; import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint } from 'vs/workbench/api/node/extHostTypes'; +import { generateUuid } from 'vs/base/common/uuid'; export class ExtHostDebugService implements ExtHostDebugServiceShape { @@ -106,16 +107,22 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { if (delta.added) { for (const bpd of delta.added) { - let bp: vscode.Breakpoint; - if (bpd.type === 'function') { - bp = new FunctionBreakpoint(bpd.functionName, bpd.enabled, bpd.condition, bpd.hitCondition); - } else { - const uri = URI.revive(bpd.uri); - bp = new SourceBreakpoint(new Location(uri, new Position(bpd.line, bpd.character)), bpd.enabled, bpd.condition, bpd.hitCondition); + + if (!this._breakpoints.has(bpd.id)) { + let bp: vscode.Breakpoint; + if (bpd.type === 'function') { + bp = new FunctionBreakpoint(bpd.functionName, bpd.enabled, bpd.condition, bpd.hitCondition); + } else { + const uri = URI.revive(bpd.uri); + bp = new SourceBreakpoint(new Location(uri, new Position(bpd.line, bpd.character)), bpd.enabled, bpd.condition, bpd.hitCondition); + } + bp['_id'] = bpd.id; + this._breakpoints.set(bpd.id, bp); + a.push(bp); + } - bp['_id'] = bpd.id; - this._breakpoints.set(bpd.id, bp); - a.push(bp); + + } } @@ -157,25 +164,31 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { this.startBreakpoints(); - // assign temporary ids for brand new breakpoints + // 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)) { + if (this._breakpoints.has(id)) { + // already there + } else { breakpoints.push(bp); } } else { - // no id -> assign temp id + id = generateUuid(); + bp['_id'] = id; + this._breakpoints.set(id, bp); breakpoints.push(bp); } } - // convert to DTOs + // send notification for added breakpoints + this.fireBreakpointChanges(breakpoints, [], []); + + // convert added breakpoints to DTOs const dtos: (ISourceMultiBreakpointDto | IFunctionBreakpointDto)[] = []; const map = new Map(); - for (let i = 0; i < breakpoints.length; i++) { - const bp = breakpoints[i]; + for (const bp of breakpoints) { if (bp instanceof SourceBreakpoint) { let dto = map.get(bp.location.uri.toString()); if (!dto) { @@ -188,7 +201,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { dtos.push(dto); } dto.lines.push({ - index: i, + id: bp['_id'], enabled: bp.enabled, condition: bp.condition, hitCondition: bp.hitCondition, @@ -198,7 +211,7 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { } else if (bp instanceof FunctionBreakpoint) { dtos.push({ type: 'function', - index: i, + id: bp['_id'], enabled: bp.enabled, functionName: bp.functionName, hitCondition: bp.hitCondition, @@ -207,21 +220,8 @@ export class ExtHostDebugService implements ExtHostDebugServiceShape { } } - // register with VS Code - return this._debugServiceProxy.$registerBreakpoints(dtos).then(ids => { - - // assign VS Code ids to breakpoints and store them in map - ids.forEach(id => { - const bp = breakpoints[id.index]; - bp['_id'] = id.id; - this._breakpoints.set(id.id, bp); - }); - - // send notification - this.fireBreakpointChanges(breakpoints, [], []); - - return void 0; - }); + // send DTOs to VS Code + return this._debugServiceProxy.$registerBreakpoints(dtos); } public removeBreakpoints(breakpoints0: vscode.Breakpoint[]): TPromise { diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index cffb72a71e5..7c951a07014 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -223,6 +223,7 @@ export interface IEnablement extends ITreeElement { } export interface IRawBreakpoint { + id?: string; lineNumber: number; column?: number; enabled?: boolean; @@ -523,7 +524,7 @@ export interface IDebugService { /** * Adds new breakpoints to the model for the file specified with the uri. Notifies debug adapter of breakpoint changes. */ - addBreakpoints(uri: uri, rawBreakpoints: IRawBreakpoint[]): TPromise; + addBreakpoints(uri: uri, rawBreakpoints: IRawBreakpoint[]): TPromise; /** * Updates the breakpoints. @@ -551,7 +552,7 @@ export interface IDebugService { /** * Adds a new function breakpoint for the given name. */ - addFunctionBreakpoint(name?: string): IFunctionBreakpoint; + addFunctionBreakpoint(name?: string, id?: string): void; /** * Renames an already existing function breakpoint. diff --git a/src/vs/workbench/parts/debug/common/debugModel.ts b/src/vs/workbench/parts/debug/common/debugModel.ts index 16dd4a8a7da..7b162f1caab 100644 --- a/src/vs/workbench/parts/debug/common/debugModel.ts +++ b/src/vs/workbench/parts/debug/common/debugModel.ts @@ -675,7 +675,6 @@ export class Breakpoint implements IBreakpoint { public message: string; public endLineNumber: number; public endColumn: number; - private id: string; constructor( public uri: uri, @@ -684,13 +683,13 @@ export class Breakpoint implements IBreakpoint { public enabled: boolean, public condition: string, public hitCondition: string, - public adapterData: any + public adapterData: any, + private id = generateUuid() ) { if (enabled === undefined) { this.enabled = true; } this.verified = false; - this.id = generateUuid(); } public getId(): string { @@ -700,13 +699,11 @@ export class Breakpoint implements IBreakpoint { export class FunctionBreakpoint implements IFunctionBreakpoint { - private id: string; public verified: boolean; public idFromAdapter: number; - constructor(public name: string, public enabled: boolean, public hitCondition: string) { + constructor(public name: string, public enabled: boolean, public hitCondition: string, private id = generateUuid()) { this.verified = false; - this.id = generateUuid(); } public getId(): string { @@ -867,7 +864,7 @@ export class Model implements IModel { } public addBreakpoints(uri: uri, rawData: IRawBreakpoint[], fireEvent = true): Breakpoint[] { - const newBreakpoints = rawData.map(rawBp => new Breakpoint(uri, rawBp.lineNumber, rawBp.column, rawBp.enabled, rawBp.condition, rawBp.hitCondition, undefined)); + const newBreakpoints = rawData.map(rawBp => new Breakpoint(uri, rawBp.lineNumber, rawBp.column, rawBp.enabled, rawBp.condition, rawBp.hitCondition, undefined, rawBp.id)); this.breakpoints = this.breakpoints.concat(newBreakpoints); this.breakpointsActivated = true; this.sortAndDeDup(); @@ -957,8 +954,8 @@ export class Model implements IModel { this._onDidChangeBreakpoints.fire({ changed: changed }); } - public addFunctionBreakpoint(functionName: string): FunctionBreakpoint { - const newFunctionBreakpoint = new FunctionBreakpoint(functionName, true, null); + public addFunctionBreakpoint(functionName: string, id: string): FunctionBreakpoint { + const newFunctionBreakpoint = new FunctionBreakpoint(functionName, true, null, id); this.functionBreakpoints.push(newFunctionBreakpoint); this._onDidChangeBreakpoints.fire({ added: [newFunctionBreakpoint] }); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 04259534cc6..5afd2c0b374 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -580,13 +580,11 @@ export class DebugService implements debug.IDebugService { return this.sendAllBreakpoints(); } - public addBreakpoints(uri: uri, rawBreakpoints: debug.IRawBreakpoint[]): TPromise { - const bps = this.model.addBreakpoints(uri, rawBreakpoints); + public addBreakpoints(uri: uri, rawBreakpoints: debug.IRawBreakpoint[]): TPromise { + this.model.addBreakpoints(uri, rawBreakpoints); rawBreakpoints.forEach(rbp => aria.status(nls.localize('breakpointAdded', "Added breakpoint, line {0}, file {1}", rbp.lineNumber, uri.fsPath))); - return this.sendBreakpoints(uri).then(_ => { - return bps; - }); + return this.sendBreakpoints(uri); } public updateBreakpoints(uri: uri, data: { [id: string]: DebugProtocol.Breakpoint }): void { @@ -609,10 +607,9 @@ export class DebugService implements debug.IDebugService { return this.sendAllBreakpoints(); } - public addFunctionBreakpoint(name?: string): debug.IFunctionBreakpoint { - const newFunctionBreakpoint = this.model.addFunctionBreakpoint(name || ''); + public addFunctionBreakpoint(name?: string, id?: string): void { + const newFunctionBreakpoint = this.model.addFunctionBreakpoint(name || '', id); this.viewModel.setSelectedFunctionBreakpoint(newFunctionBreakpoint); - return newFunctionBreakpoint; } public renameFunctionBreakpoint(id: string, newFunctionName: string): TPromise { diff --git a/src/vs/workbench/parts/debug/test/common/mockDebug.ts b/src/vs/workbench/parts/debug/test/common/mockDebug.ts index 737abebf932..7d722ef668d 100644 --- a/src/vs/workbench/parts/debug/test/common/mockDebug.ts +++ b/src/vs/workbench/parts/debug/test/common/mockDebug.ts @@ -39,7 +39,7 @@ export class MockDebugService implements debug.IDebugService { public focusStackFrame(focusedStackFrame: debug.IStackFrame): void { } - public addBreakpoints(uri: uri, rawBreakpoints: debug.IRawBreakpoint[]): TPromise { + public addBreakpoints(uri: uri, rawBreakpoints: debug.IRawBreakpoint[]): TPromise { return TPromise.as(null); } @@ -57,9 +57,7 @@ export class MockDebugService implements debug.IDebugService { return TPromise.as(null); } - public addFunctionBreakpoint(): debug.IFunctionBreakpoint { - return null; - } + public addFunctionBreakpoint(): void { } public moveWatchExpression(id: string, position: number): void { }