diff --git a/src/vs/vscode.d.ts b/src/vs/vscode.d.ts index 3c8c3c4a8666bf769dd39935e3abedfff0637435..dfb359ce50372c4917041f81375326a7a8ffb612 100644 --- a/src/vs/vscode.d.ts +++ b/src/vs/vscode.d.ts @@ -9341,7 +9341,7 @@ declare module 'vscode' { constructor(port: number, host?: string); } - export type DebugAdapterDescriptor = DebugAdapterExecutable | DebugAdapterServer; + export type DebugAdapterDescriptor = DebugAdapterExecutable | DebugAdapterServer | DebugAdapterInlineImplementation; export interface DebugAdapterDescriptorFactory { /** diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index a439a65a944ac6c2b489e2b10fb1b62b46c8721c..b1e7ef9e457b8fc4458dc918dbdc671267331813 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -607,6 +607,35 @@ declare module 'vscode' { export function asDebugSourceUri(source: DebugSource, session?: DebugSession): Uri; } + /** + * A DebugProtocolMessage is an opaque stand-in type for the [ProtocolMessage](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage) type defined in the Debug Adapter Protocol. + */ + interface DebugProtocolMessage { + // Properties: see details [here](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage). + } + + /** + * A debug adapter that implements the Debug Adapter Protocol can be registered with VS Code if it implements this interface. + */ + interface DebugAdapter { + + readonly onSendMessage: Event; + readonly onError: Event; + + handleMessage(message: DebugProtocolMessage): void; + } + + /** + * A debug adapter descriptor for an inline implementation. + */ + export class DebugAdapterInlineImplementation { + + /** + * Create a descriptor for an inline implementation of a debug adapter. + */ + constructor(implementation: DebugAdapter); + } + // deprecated export interface DebugConfigurationProvider { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index c35de421c574b17238509ea76ab3cdd21dadb038..b174460497c8a20037584e29f8883ad92cf19de8 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -857,6 +857,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I ConfigurationTarget: extHostTypes.ConfigurationTarget, DebugAdapterExecutable: extHostTypes.DebugAdapterExecutable, DebugAdapterServer: extHostTypes.DebugAdapterServer, + DebugAdapterInlineImplementation: extHostTypes.DebugAdapterInlineImplementation, DecorationRangeBehavior: extHostTypes.DecorationRangeBehavior, Diagnostic: extHostTypes.Diagnostic, DiagnosticRelatedInformation: extHostTypes.DiagnosticRelatedInformation, diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index ea2d1da1b3dd48ee15f3d779def5648348e6ea47..5d6b6021dbec5b5c808b91b0c836f12d4ce7dc14 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -11,12 +11,12 @@ import { MainContext, MainThreadDebugServiceShape, ExtHostDebugServiceShape, DebugSessionUUID, IBreakpointsDeltaDto, ISourceMultiBreakpointDto, IFunctionBreakpointDto, IDebugSessionDto } from 'vs/workbench/api/common/extHost.protocol'; -import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer, DebugAdapterExecutable, DataBreakpoint, DebugConsoleMode } from 'vs/workbench/api/common/extHostTypes'; +import { Disposable, Position, Location, SourceBreakpoint, FunctionBreakpoint, DebugAdapterServer, DebugAdapterExecutable, DataBreakpoint, DebugConsoleMode, DebugAdapterInlineImplementation } from 'vs/workbench/api/common/extHostTypes'; import { AbstractDebugAdapter } from 'vs/workbench/contrib/debug/common/abstractDebugAdapter'; import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; import { IExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService'; import { ExtHostDocumentsAndEditors, IExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; -import { IDebuggerContribution, IConfig, IDebugAdapter, IDebugAdapterServer, IDebugAdapterExecutable, IAdapterDescriptor, IDebugAdapterImplementation } from 'vs/workbench/contrib/debug/common/debug'; +import { IDebuggerContribution, IConfig, IDebugAdapter, IDebugAdapterServer, IDebugAdapterExecutable, IAdapterDescriptor, IDebugAdapterImpl } from 'vs/workbench/contrib/debug/common/debug'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { AbstractVariableResolverService } from 'vs/workbench/services/configurationResolver/common/variableResolver'; import { ExtHostConfigProvider, IExtHostConfiguration } from '../common/extHostConfiguration'; @@ -697,15 +697,6 @@ export class ExtHostDebugServiceBase implements IExtHostDebugService, ExtHostDeb private convertToDto(x: vscode.DebugAdapterDescriptor | undefined): IAdapterDescriptor { if (x instanceof DebugAdapterExecutable) { - - const a = x; - if (a['implementation']) { - return { - type: 'implementation', - implementation: a['implementation'] - }; - } - return { type: 'executable', command: x.command, @@ -718,12 +709,12 @@ export class ExtHostDebugServiceBase implements IExtHostDebugService, ExtHostDeb port: x.port, host: x.host }; - } else /* if (x instanceof DebugAdapterImplementation) { - return { + } else if (x instanceof DebugAdapterInlineImplementation) { + return { type: 'implementation', implementation: x.implementation }; - } else */ { + } else { throw new Error('convertToDto unexpected type'); } } @@ -1050,58 +1041,40 @@ class MultiTracker implements vscode.DebugAdapterTracker { } } -interface IDapTransport { - start(cb: (msg: DebugProtocol.ProtocolMessage) => void, errorcb: (event: DebugProtocol.Event) => void): void; - send(message: DebugProtocol.ProtocolMessage): void; - stop(): void; -} - /* - * experimental: call directly into a debug adapter implementation + * Call directly into a debug adapter implementation */ -class DirectDebugAdapter extends AbstractDebugAdapter implements IDapTransport { - - private _sendUp!: (msg: DebugProtocol.ProtocolMessage) => void; +class DirectDebugAdapter extends AbstractDebugAdapter { - constructor(implementation: any) { + constructor(private implementation: vscode.DebugAdapter) { super(); - if (implementation.__setTransport) { - implementation.__setTransport(this); + + if (this.implementation.onSendMessage) { + implementation.onSendMessage((message: DebugProtocol.ProtocolMessage) => { + this.acceptMessage(message); + }); } - } - // IDapTransport - start(cb: (msg: DebugProtocol.ProtocolMessage) => void, errorcb: (event: DebugProtocol.Event) => void) { - this._sendUp = cb; + if (this.implementation.onError) { + implementation.onError((error: Error) => { + this._onError.fire(error); + }); + } } - // AbstractDebugAdapter startSession(): Promise { return Promise.resolve(undefined); } - // AbstractDebugAdapter - // VSCode -> DA sendMessage(message: DebugProtocol.ProtocolMessage): void { - this._sendUp(message); + if (this.implementation.handleMessage) { + this.implementation.handleMessage(message); + } } - // AbstractDebugAdapter stopSession(): Promise { - this.stop(); return Promise.resolve(undefined); } - - // IDapTransport - // DA -> VSCode - send(message: DebugProtocol.ProtocolMessage) { - this.acceptMessage(message); - } - - // IDapTransport - stop(): void { - throw new Error('Method not implemented.'); - } } @@ -1117,4 +1090,3 @@ export class WorkerExtHostDebugService extends ExtHostDebugServiceBase { super(extHostRpcService, workspaceService, extensionService, editorsService, configurationService, commandService); } } - diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index bc50900c901808a361a9dce9bd6ed7515d164e00..4573846bd4d261cabf04d501fa5792cf62f78830 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2250,16 +2250,14 @@ export class DebugAdapterServer implements vscode.DebugAdapterServer { } } -/* @es5ClassCompat -export class DebugAdapterImplementation implements vscode.DebugAdapterImplementation { - readonly implementation: any; +export class DebugAdapterInlineImplementation implements vscode.DebugAdapterInlineImplementation { + readonly implementation: vscode.DebugAdapter; - constructor(transport: any) { - this.implementation = transport; + constructor(impl: vscode.DebugAdapter) { + this.implementation = impl; } } -*/ export enum LogLevel { Trace = 1, diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index 4ba0c58f1178b24b40eb63e3c398984e23212244..a4745a8965d329c205f8dd73dc4b67865deda317 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -546,12 +546,19 @@ export interface IDebugAdapterServer { readonly host?: string; } -export interface IDebugAdapterImplementation { +export interface IDebugAdapterInlineImpl { + readonly onSendMessage: Event; + readonly onError: Event; + + handleMessage(message: DebugProtocol.Message): void; +} + +export interface IDebugAdapterImpl { readonly type: 'implementation'; - readonly implementation: any; + readonly implementation: IDebugAdapterInlineImpl; } -export type IAdapterDescriptor = IDebugAdapterExecutable | IDebugAdapterServer | IDebugAdapterImplementation; +export type IAdapterDescriptor = IDebugAdapterExecutable | IDebugAdapterServer | IDebugAdapterImpl; export interface IPlatformSpecificAdapterContribution { program?: string;