From c233bf87bcf1bf1794a6aae62b01a09506b67d72 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Mon, 17 Aug 2020 12:28:51 +0200 Subject: [PATCH] add API to access DAP breakpoints; see #99716 --- src/vs/vscode.proposed.d.ts | 11 +++++++ .../api/browser/mainThreadDebugService.ts | 8 +++++ .../workbench/api/common/extHost.protocol.ts | 1 + .../api/common/extHostDebugService.ts | 4 +++ .../contrib/debug/browser/debugSession.ts | 4 +++ .../workbench/contrib/debug/common/debug.ts | 1 + .../contrib/debug/common/debugModel.ts | 29 +++++++++++++++++++ .../contrib/debug/test/common/mockDebug.ts | 3 ++ 8 files changed, 61 insertions(+) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 10e4324721b..843913db162 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -752,6 +752,17 @@ declare module 'vscode' { compact?: boolean; } + /** + * A DebugProtocolBreakpoint is an opaque stand-in type for the [Breakpoint](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Breakpoint) type defined in the Debug Adapter Protocol. + */ + export interface DebugProtocolBreakpoint { + // Properties: see details [here](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Breakpoint). + } + + export interface DebugSession { + getDebugProtocolBreakpoint(breakpoint: Breakpoint): DebugProtocolBreakpoint | undefined; + } + // deprecated debug API export interface DebugConfigurationProvider { diff --git a/src/vs/workbench/api/browser/mainThreadDebugService.ts b/src/vs/workbench/api/browser/mainThreadDebugService.ts index 907f2886311..a723b1a38f1 100644 --- a/src/vs/workbench/api/browser/mainThreadDebugService.ts +++ b/src/vs/workbench/api/browser/mainThreadDebugService.ts @@ -264,6 +264,14 @@ export class MainThreadDebugService implements MainThreadDebugServiceShape, IDeb return Promise.reject(new Error('debug session not found')); } + public $getDebugProtocolBreakpoint(sessionId: DebugSessionUUID, breakpoinId: string): Promise { + const session = this.debugService.getModel().getSession(sessionId, true); + if (session) { + return Promise.resolve(session.getDebugProtocolBreakpoint(breakpoinId)); + } + return Promise.reject(new Error('debug session not found')); + } + public $stopDebugging(sessionId: DebugSessionUUID | undefined): Promise { if (sessionId) { const session = this.debugService.getModel().getSession(sessionId, true); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index fcee75d3127..512dbb8d5bc 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -879,6 +879,7 @@ export interface MainThreadDebugServiceShape extends IDisposable { $stopDebugging(sessionId: DebugSessionUUID | undefined): Promise; $setDebugSessionName(id: DebugSessionUUID, name: string): void; $customDebugAdapterRequest(id: DebugSessionUUID, command: string, args: any): Promise; + $getDebugProtocolBreakpoint(id: DebugSessionUUID, breakpoinId: string): Promise; $appendDebugConsole(value: string): void; $startBreakpointEvents(): void; $registerBreakpoints(breakpoints: Array): Promise; diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index 82121bcb2c6..1e6b3429aa4 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -957,6 +957,10 @@ export class ExtHostDebugSession implements vscode.DebugSession { public customRequest(command: string, args: any): Promise { return this._debugServiceProxy.$customDebugAdapterRequest(this._id, command, args); } + + public getDebugProtocolBreakpoint(breakpoint: vscode.Breakpoint): vscode.DebugProtocolBreakpoint | undefined { + return this._debugServiceProxy.$getDebugProtocolBreakpoint(this._id, breakpoint.id); + } } export class ExtHostDebugConsole implements vscode.DebugConsole { diff --git a/src/vs/workbench/contrib/debug/browser/debugSession.ts b/src/vs/workbench/contrib/debug/browser/debugSession.ts index 19c471f74bd..22373d30863 100644 --- a/src/vs/workbench/contrib/debug/browser/debugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/debugSession.ts @@ -440,6 +440,10 @@ export class DebugSession implements IDebugSession { return distinct(positions, p => `${p.lineNumber}:${p.column}`); } + getDebugProtocolBreakpoint(breakpointId: string): DebugProtocol.Breakpoint | undefined { + return this.model.getDebugProtocolBreakpoint(breakpointId, this.getId()); + } + customRequest(request: string, args: any): Promise { if (!this.raw) { throw new Error(localize('noDebugAdapter', "No debug adapter, can not send '{0}'", request)); diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 8353ae1ab17..885b800c4ae 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -224,6 +224,7 @@ export interface IDebugSession extends ITreeElement { sendDataBreakpoints(dbps: IDataBreakpoint[]): Promise; sendExceptionBreakpoints(exbpts: IExceptionBreakpoint[]): Promise; breakpointsLocations(uri: uri, lineNumber: number): Promise; + getDebugProtocolBreakpoint(breakpointId: string): DebugProtocol.Breakpoint | undefined; stackTrace(threadId: number, startFrame: number, levels: number, token: CancellationToken): Promise; exceptionInfo(threadId: number): Promise; diff --git a/src/vs/workbench/contrib/debug/common/debugModel.ts b/src/vs/workbench/contrib/debug/common/debugModel.ts index 0a5620c8d4b..80060824d0d 100644 --- a/src/vs/workbench/contrib/debug/common/debugModel.ts +++ b/src/vs/workbench/contrib/debug/common/debugModel.ts @@ -597,6 +597,27 @@ export abstract class BaseBreakpoint extends Enablement implements IBaseBreakpoi return data ? data.id : undefined; } + getDebugProtocolBreakpoint(sessionId: string): DebugProtocol.Breakpoint | undefined { + const data = this.sessionData.get(sessionId); + if (data) { + const bp: DebugProtocol.Breakpoint = { + id: data.id, + verified: data.verified, + message: data.message, + source: data.source, + line: data.line, + column: data.column, + endLine: data.endLine, + endColumn: data.endColumn, + instructionReference: data.instructionReference, + offset: data.offset + // TODO: copy additional debug adapter data + }; + return bp; + } + return undefined; + } + toJSON(): any { const result = Object.create(null); result.enabled = this.enabled; @@ -1094,6 +1115,14 @@ export class DebugModel implements IDebugModel { }); } + getDebugProtocolBreakpoint(breakpointId: string, sessionId: string): DebugProtocol.Breakpoint | undefined { + const bp = this.breakpoints.find(bp => bp.getId()); + if (bp) { + return bp.getDebugProtocolBreakpoint(sessionId); + } + return undefined; + } + private sortAndDeDup(): void { this.breakpoints = this.breakpoints.sort((first, second) => { if (first.uri.toString() !== second.uri.toString()) { diff --git a/src/vs/workbench/contrib/debug/test/common/mockDebug.ts b/src/vs/workbench/contrib/debug/test/common/mockDebug.ts index f3057da0e95..9f4002da8b9 100644 --- a/src/vs/workbench/contrib/debug/test/common/mockDebug.ts +++ b/src/vs/workbench/contrib/debug/test/common/mockDebug.ts @@ -293,6 +293,9 @@ export class MockSession implements IDebugSession { sendExceptionBreakpoints(exbpts: IExceptionBreakpoint[]): Promise { throw new Error('Method not implemented.'); } + getDebugProtocolBreakpoint(breakpointId: string): DebugProtocol.Breakpoint | undefined { + throw new Error('Method not implemented.'); + } customRequest(request: string, args: any): Promise { throw new Error('Method not implemented.'); }