Path: blob/main/src/vs/platform/debug/common/extensionHostDebugIpc.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Emitter, Event } from '../../../base/common/event.js';6import { Disposable } from '../../../base/common/lifecycle.js';7import { IChannel, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';8import { IAttachSessionEvent, ICloseSessionEvent, IExtensionHostDebugService, IOpenExtensionWindowResult, IReloadSessionEvent, ITerminateSessionEvent } from './extensionHostDebug.js';910export class ExtensionHostDebugBroadcastChannel<TContext> implements IServerChannel<TContext> {1112static readonly ChannelName = 'extensionhostdebugservice';1314private readonly _onCloseEmitter = new Emitter<ICloseSessionEvent>();15private readonly _onReloadEmitter = new Emitter<IReloadSessionEvent>();16private readonly _onTerminateEmitter = new Emitter<ITerminateSessionEvent>();17private readonly _onAttachEmitter = new Emitter<IAttachSessionEvent>();1819call(ctx: TContext, command: string, arg?: any): Promise<any> {20switch (command) {21case 'close':22return Promise.resolve(this._onCloseEmitter.fire({ sessionId: arg[0] }));23case 'reload':24return Promise.resolve(this._onReloadEmitter.fire({ sessionId: arg[0] }));25case 'terminate':26return Promise.resolve(this._onTerminateEmitter.fire({ sessionId: arg[0] }));27case 'attach':28return Promise.resolve(this._onAttachEmitter.fire({ sessionId: arg[0], port: arg[1], subId: arg[2] }));29}30throw new Error('Method not implemented.');31}3233listen(ctx: TContext, event: string, arg?: any): Event<any> {34switch (event) {35case 'close':36return this._onCloseEmitter.event;37case 'reload':38return this._onReloadEmitter.event;39case 'terminate':40return this._onTerminateEmitter.event;41case 'attach':42return this._onAttachEmitter.event;43}44throw new Error('Method not implemented.');45}46}4748export class ExtensionHostDebugChannelClient extends Disposable implements IExtensionHostDebugService {4950declare readonly _serviceBrand: undefined;5152constructor(private channel: IChannel) {53super();54}5556reload(sessionId: string): void {57this.channel.call('reload', [sessionId]);58}5960get onReload(): Event<IReloadSessionEvent> {61return this.channel.listen('reload');62}6364close(sessionId: string): void {65this.channel.call('close', [sessionId]);66}6768get onClose(): Event<ICloseSessionEvent> {69return this.channel.listen('close');70}7172attachSession(sessionId: string, port: number, subId?: string): void {73this.channel.call('attach', [sessionId, port, subId]);74}7576get onAttachSession(): Event<IAttachSessionEvent> {77return this.channel.listen('attach');78}7980terminateSession(sessionId: string, subId?: string): void {81this.channel.call('terminate', [sessionId, subId]);82}8384get onTerminateSession(): Event<ITerminateSessionEvent> {85return this.channel.listen('terminate');86}8788openExtensionDevelopmentHostWindow(args: string[], debugRenderer: boolean): Promise<IOpenExtensionWindowResult> {89return this.channel.call('openExtensionDevelopmentHostWindow', [args, debugRenderer]);90}9192attachToCurrentWindowRenderer(windowId: number): Promise<IOpenExtensionWindowResult> {93return this.channel.call('attachToCurrentWindowRenderer', [windowId]);94}95}969798