Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/debug/common/extensionHostDebugIpc.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Emitter, Event } from '../../../base/common/event.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
import { IChannel, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
9
import { IAttachSessionEvent, ICloseSessionEvent, IExtensionHostDebugService, IOpenExtensionWindowResult, IReloadSessionEvent, ITerminateSessionEvent } from './extensionHostDebug.js';
10
11
export class ExtensionHostDebugBroadcastChannel<TContext> implements IServerChannel<TContext> {
12
13
static readonly ChannelName = 'extensionhostdebugservice';
14
15
private readonly _onCloseEmitter = new Emitter<ICloseSessionEvent>();
16
private readonly _onReloadEmitter = new Emitter<IReloadSessionEvent>();
17
private readonly _onTerminateEmitter = new Emitter<ITerminateSessionEvent>();
18
private readonly _onAttachEmitter = new Emitter<IAttachSessionEvent>();
19
20
call(ctx: TContext, command: string, arg?: any): Promise<any> {
21
switch (command) {
22
case 'close':
23
return Promise.resolve(this._onCloseEmitter.fire({ sessionId: arg[0] }));
24
case 'reload':
25
return Promise.resolve(this._onReloadEmitter.fire({ sessionId: arg[0] }));
26
case 'terminate':
27
return Promise.resolve(this._onTerminateEmitter.fire({ sessionId: arg[0] }));
28
case 'attach':
29
return Promise.resolve(this._onAttachEmitter.fire({ sessionId: arg[0], port: arg[1], subId: arg[2] }));
30
}
31
throw new Error('Method not implemented.');
32
}
33
34
listen(ctx: TContext, event: string, arg?: any): Event<any> {
35
switch (event) {
36
case 'close':
37
return this._onCloseEmitter.event;
38
case 'reload':
39
return this._onReloadEmitter.event;
40
case 'terminate':
41
return this._onTerminateEmitter.event;
42
case 'attach':
43
return this._onAttachEmitter.event;
44
}
45
throw new Error('Method not implemented.');
46
}
47
}
48
49
export class ExtensionHostDebugChannelClient extends Disposable implements IExtensionHostDebugService {
50
51
declare readonly _serviceBrand: undefined;
52
53
constructor(private channel: IChannel) {
54
super();
55
}
56
57
reload(sessionId: string): void {
58
this.channel.call('reload', [sessionId]);
59
}
60
61
get onReload(): Event<IReloadSessionEvent> {
62
return this.channel.listen('reload');
63
}
64
65
close(sessionId: string): void {
66
this.channel.call('close', [sessionId]);
67
}
68
69
get onClose(): Event<ICloseSessionEvent> {
70
return this.channel.listen('close');
71
}
72
73
attachSession(sessionId: string, port: number, subId?: string): void {
74
this.channel.call('attach', [sessionId, port, subId]);
75
}
76
77
get onAttachSession(): Event<IAttachSessionEvent> {
78
return this.channel.listen('attach');
79
}
80
81
terminateSession(sessionId: string, subId?: string): void {
82
this.channel.call('terminate', [sessionId, subId]);
83
}
84
85
get onTerminateSession(): Event<ITerminateSessionEvent> {
86
return this.channel.listen('terminate');
87
}
88
89
openExtensionDevelopmentHostWindow(args: string[], debugRenderer: boolean): Promise<IOpenExtensionWindowResult> {
90
return this.channel.call('openExtensionDevelopmentHostWindow', [args, debugRenderer]);
91
}
92
93
attachToCurrentWindowRenderer(windowId: number): Promise<IOpenExtensionWindowResult> {
94
return this.channel.call('attachToCurrentWindowRenderer', [windowId]);
95
}
96
}
97
98