|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | | -import { Event, Emitter } from 'vs/base/common/event'; |
7 | | -import { IWindowService } from 'vs/platform/windows/common/windows'; |
8 | 6 | import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; |
9 | | -import { IExtensionHostDebugService, IAttachSessionEvent, ITerminateSessionEvent, ILogToSessionEvent, IReloadSessionEvent, ICloseSessionEvent } from 'vs/workbench/services/extensions/common/extensionHostDebug'; |
10 | | -import { IRemoteConsoleLog } from 'vs/base/common/console'; |
11 | | -import { ipcRenderer as ipc } from 'electron'; |
| 7 | +import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug'; |
| 8 | +import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService'; |
| 9 | +import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc'; |
12 | 10 |
|
13 | | -interface IReloadBroadcast extends IReloadSessionEvent { |
14 | | - type: 'vscode:extensionReload'; |
15 | | -} |
16 | | - |
17 | | -interface IAttachSessionBroadcast extends IAttachSessionEvent { |
18 | | - type: 'vscode:extensionAttach'; |
19 | | -} |
20 | | - |
21 | | -interface ICloseBroadcast extends ICloseSessionEvent { |
22 | | - type: 'vscode:extensionCloseExtensionHost'; |
23 | | -} |
24 | | - |
25 | | -interface ILogToSessionBroadcast extends ILogToSessionEvent { |
26 | | - type: 'vscode:extensionLog'; |
27 | | -} |
28 | | - |
29 | | -interface ITerminateSessionBroadcast extends ITerminateSessionEvent { |
30 | | - type: 'vscode:extensionTerminate'; |
31 | | -} |
32 | | - |
33 | | -const CHANNEL = 'vscode:extensionHostDebug'; |
34 | | - |
35 | | -class ExtensionHostDebugService implements IExtensionHostDebugService { |
36 | | - _serviceBrand: any; |
37 | | - |
38 | | - private windowId: number; |
39 | | - private readonly _onReload = new Emitter<IReloadSessionEvent>(); |
40 | | - private readonly _onClose = new Emitter<ICloseSessionEvent>(); |
41 | | - private readonly _onAttachSession = new Emitter<IAttachSessionEvent>(); |
42 | | - private readonly _onLogToSession = new Emitter<ILogToSessionEvent>(); |
43 | | - private readonly _onTerminateSession = new Emitter<ITerminateSessionEvent>(); |
| 11 | +export class ExtensionHostDebugService extends ExtensionHostDebugChannelClient { |
44 | 12 |
|
45 | 13 | constructor( |
46 | | - @IWindowService readonly windowService: IWindowService, |
| 14 | + @IMainProcessService readonly windowService: IMainProcessService, |
47 | 15 | ) { |
48 | | - this.windowId = windowService.windowId; |
49 | | - |
50 | | - ipc.on(CHANNEL, (_: unknown, broadcast: IReloadBroadcast | ICloseBroadcast | IAttachSessionBroadcast | ILogToSessionBroadcast | ITerminateSessionBroadcast) => { |
51 | | - switch (broadcast.type) { |
52 | | - case 'vscode:extensionReload': |
53 | | - this._onReload.fire(broadcast); |
54 | | - break; |
55 | | - case 'vscode:extensionCloseExtensionHost': |
56 | | - this._onClose.fire(broadcast); |
57 | | - break; |
58 | | - case 'vscode:extensionAttach': |
59 | | - this._onAttachSession.fire(broadcast); |
60 | | - break; |
61 | | - case 'vscode:extensionLog': |
62 | | - this._onLogToSession.fire(broadcast); |
63 | | - break; |
64 | | - case 'vscode:extensionTerminate': |
65 | | - this._onTerminateSession.fire(broadcast); |
66 | | - break; |
67 | | - } |
68 | | - }); |
69 | | - } |
70 | | - |
71 | | - reload(sessionId: string): void { |
72 | | - ipc.send(CHANNEL, this.windowId, <IReloadBroadcast>{ |
73 | | - type: 'vscode:extensionReload', |
74 | | - sessionId |
75 | | - }); |
76 | | - } |
77 | | - |
78 | | - get onReload(): Event<IReloadSessionEvent> { |
79 | | - return this._onReload.event; |
80 | | - } |
81 | | - |
82 | | - close(sessionId: string): void { |
83 | | - ipc.send(CHANNEL, this.windowId, <ICloseBroadcast>{ |
84 | | - type: 'vscode:extensionCloseExtensionHost', |
85 | | - sessionId |
86 | | - }); |
87 | | - } |
88 | | - |
89 | | - get onClose(): Event<ICloseSessionEvent> { |
90 | | - return this._onClose.event; |
91 | | - } |
92 | | - |
93 | | - attachSession(sessionId: string, port: number, subId?: string): void { |
94 | | - ipc.send(CHANNEL, this.windowId, <IAttachSessionBroadcast>{ |
95 | | - type: 'vscode:extensionAttach', |
96 | | - sessionId, |
97 | | - port, |
98 | | - subId |
99 | | - }); |
100 | | - } |
101 | | - |
102 | | - get onAttachSession(): Event<IAttachSessionEvent> { |
103 | | - return this._onAttachSession.event; |
104 | | - } |
105 | | - |
106 | | - logToSession(sessionId: string, log: IRemoteConsoleLog): void { |
107 | | - ipc.send(CHANNEL, this.windowId, <ILogToSessionBroadcast>{ |
108 | | - type: 'vscode:extensionLog', |
109 | | - sessionId, |
110 | | - log |
111 | | - }); |
112 | | - } |
113 | | - |
114 | | - get onLogToSession(): Event<ILogToSessionEvent> { |
115 | | - return this._onLogToSession.event; |
116 | | - } |
117 | | - |
118 | | - terminateSession(sessionId: string, subId?: string): void { |
119 | | - ipc.send(CHANNEL, this.windowId, <ITerminateSessionBroadcast>{ |
120 | | - type: 'vscode:extensionTerminate', |
121 | | - sessionId, |
122 | | - subId |
123 | | - }); |
124 | | - } |
125 | | - |
126 | | - get onTerminateSession(): Event<ITerminateSessionEvent> { |
127 | | - return this._onTerminateSession.event; |
| 16 | + super(windowService.getChannel(ExtensionHostDebugBroadcastChannel.ChannelName)); |
128 | 17 | } |
129 | 18 | } |
130 | 19 |
|
|
0 commit comments