提交 cf81214e 编写于 作者: A Andre Weinand

extension API for implementing DA in extension; see #85544

上级 1172e3b9
......@@ -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 {
/**
......
......@@ -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<DebugProtocolMessage>;
readonly onError: Event<Error>;
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 {
......
......@@ -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,
......
......@@ -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 = <any>x;
if (a['implementation']) {
return <IDebugAdapterImplementation>{
type: 'implementation',
implementation: a['implementation']
};
}
return <IDebugAdapterExecutable>{
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 <IDebugAdapterImplementation>{
} else if (x instanceof DebugAdapterInlineImplementation) {
return <IDebugAdapterImpl>{
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<void> {
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<void> {
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);
}
}
......@@ -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,
......
......@@ -546,12 +546,19 @@ export interface IDebugAdapterServer {
readonly host?: string;
}
export interface IDebugAdapterImplementation {
export interface IDebugAdapterInlineImpl {
readonly onSendMessage: Event<DebugProtocol.Message>;
readonly onError: Event<Error>;
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册