Skip to content

Commit fb0e9f7

Browse files
committed
cleanup ExtensionHostDebugService
1 parent 5bf08bd commit fb0e9f7

9 files changed

Lines changed: 77 additions & 187 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { DiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsIpc'
8686
import { FileService } from 'vs/platform/files/common/fileService';
8787
import { IFileService } from 'vs/platform/files/common/files';
8888
import { DiskFileSystemProvider } from 'vs/platform/files/node/diskFileSystemProvider';
89+
import { ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
8990

9091
export class CodeApplication extends Disposable {
9192

@@ -279,12 +280,6 @@ export class CodeApplication extends Disposable {
279280
}
280281
});
281282

282-
ipc.on('vscode:extensionHostDebug', (_: Event, windowId: number, broadcast: any) => {
283-
if (this.windowsMainService) {
284-
this.windowsMainService.sendToAll('vscode:extensionHostDebug', broadcast, [windowId]); // Send to all windows (except sender window)
285-
}
286-
});
287-
288283
ipc.on('vscode:toggleDevTools', (event: Event) => event.sender.toggleDevTools());
289284
ipc.on('vscode:openDevTools', (event: Event) => event.sender.openDevTools());
290285

@@ -577,6 +572,9 @@ export class CodeApplication extends Disposable {
577572
electronIpcServer.registerChannel('loglevel', logLevelChannel);
578573
sharedProcessClient.then(client => client.registerChannel('loglevel', logLevelChannel));
579574

575+
// ExtensionHost Debug broadcast service
576+
electronIpcServer.registerChannel(ExtensionHostDebugBroadcastChannel.ChannelName, new ExtensionHostDebugBroadcastChannel());
577+
580578
// Signal phase: ready (services set)
581579
this.lifecycleService.phase = LifecycleMainPhase.Ready;
582580

src/vs/workbench/services/extensions/common/extensionHostDebug.ts renamed to src/vs/platform/debug/common/extensionHostDebug.ts

File renamed without changes.

src/vs/workbench/services/extensions/common/extensionHostDebugIpc.ts renamed to src/vs/platform/debug/common/extensionHostDebugIpc.ts

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IServerChannel } from 'vs/base/parts/ipc/common/ipc';
7-
import { RemoteAgentConnectionContext } from 'vs/platform/remote/common/remoteAgentEnvironment';
8-
import { IReloadSessionEvent, ICloseSessionEvent, IAttachSessionEvent, ILogToSessionEvent, ITerminateSessionEvent } from 'vs/workbench/services/extensions/common/extensionHostDebug';
6+
import { IServerChannel, IChannel } from 'vs/base/parts/ipc/common/ipc';
7+
import { IReloadSessionEvent, ICloseSessionEvent, IAttachSessionEvent, ILogToSessionEvent, ITerminateSessionEvent, IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
98
import { Event, Emitter } from 'vs/base/common/event';
9+
import { IRemoteConsoleLog } from 'vs/base/common/console';
1010

11-
export class EchoChannel implements IServerChannel<RemoteAgentConnectionContext> {
11+
export class ExtensionHostDebugBroadcastChannel<TContext> implements IServerChannel<TContext> {
12+
13+
static readonly ChannelName = 'extensionhostdebugservice';
1214

1315
private _onCloseEmitter = new Emitter<ICloseSessionEvent>();
1416
private _onReloadEmitter = new Emitter<IReloadSessionEvent>();
1517
private _onTerminateEmitter = new Emitter<ITerminateSessionEvent>();
1618
private _onLogToEmitter = new Emitter<ILogToSessionEvent>();
1719
private _onAttachEmitter = new Emitter<IAttachSessionEvent>();
1820

19-
call(ctx: RemoteAgentConnectionContext, command: string, arg?: any): Promise<any> {
21+
call(ctx: TContext, command: string, arg?: any): Promise<any> {
2022
switch (command) {
2123
case 'close':
2224
return Promise.resolve(this._onCloseEmitter.fire({ sessionId: arg[0] }));
@@ -32,7 +34,7 @@ export class EchoChannel implements IServerChannel<RemoteAgentConnectionContext>
3234
throw new Error('Method not implemented.');
3335
}
3436

35-
listen(ctx: RemoteAgentConnectionContext, event: string, arg?: any): Event<any> {
37+
listen(ctx: TContext, event: string, arg?: any): Event<any> {
3638
switch (event) {
3739
case 'close':
3840
return this._onCloseEmitter.event;
@@ -48,3 +50,50 @@ export class EchoChannel implements IServerChannel<RemoteAgentConnectionContext>
4850
throw new Error('Method not implemented.');
4951
}
5052
}
53+
54+
export class ExtensionHostDebugChannelClient implements IExtensionHostDebugService {
55+
56+
_serviceBrand: any;
57+
58+
constructor(private channel: IChannel) { }
59+
60+
reload(sessionId: string): void {
61+
this.channel.call('reload', [sessionId]);
62+
}
63+
64+
get onReload(): Event<IReloadSessionEvent> {
65+
return this.channel.listen('reload');
66+
}
67+
68+
close(sessionId: string): void {
69+
this.channel.call('close', [sessionId]);
70+
}
71+
72+
get onClose(): Event<ICloseSessionEvent> {
73+
return this.channel.listen('close');
74+
}
75+
76+
attachSession(sessionId: string, port: number, subId?: string): void {
77+
this.channel.call('attach', [sessionId, port, subId]);
78+
}
79+
80+
get onAttachSession(): Event<IAttachSessionEvent> {
81+
return this.channel.listen('attach');
82+
}
83+
84+
logToSession(sessionId: string, log: IRemoteConsoleLog): void {
85+
this.channel.call('log', [sessionId, log]);
86+
}
87+
88+
get onLogToSession(): Event<ILogToSessionEvent> {
89+
return this.channel.listen('log');
90+
}
91+
92+
terminateSession(sessionId: string, subId?: string): void {
93+
this.channel.call('terminate', [sessionId, subId]);
94+
}
95+
96+
get onTerminateSession(): Event<ITerminateSessionEvent> {
97+
return this.channel.listen('terminate');
98+
}
99+
}

src/vs/workbench/api/browser/mainThreadConsole.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
99
import { IRemoteConsoleLog, log, parse } from 'vs/base/common/console';
1010
import { parseExtensionDevOptions } from 'vs/workbench/services/extensions/common/extensionDevOptions';
1111
import { IWindowsService } from 'vs/platform/windows/common/windows';
12-
import { IExtensionHostDebugService } from 'vs/workbench/services/extensions/common/extensionHostDebug';
12+
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
1313

1414
@extHostNamedCustomer(MainContext.MainThreadConsole)
1515
export class MainThreadConsole implements MainThreadConsoleShape {

src/vs/workbench/browser/web.simpleservices.ts

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { IRecentlyOpened, IRecent, isRecentFile, isRecentFolder } from 'vs/platf
2424
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
2525
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
2626
import { ITunnelService } from 'vs/platform/remote/common/tunnel';
27-
import { IReloadSessionEvent, IExtensionHostDebugService, ICloseSessionEvent, IAttachSessionEvent, ILogToSessionEvent, ITerminateSessionEvent } from 'vs/workbench/services/extensions/common/extensionHostDebug';
28-
import { IRemoteConsoleLog } from 'vs/base/common/console';
27+
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
2928
// tslint:disable-next-line: import-patterns
3029
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
3130
import { addDisposableListener, EventType } from 'vs/base/browser/dom';
@@ -37,9 +36,9 @@ import { ParsedArgs } from 'vs/platform/environment/common/environment';
3736
import { IProcessEnvironment } from 'vs/base/common/platform';
3837
import { toStoreData, restoreRecentlyOpened } from 'vs/platform/history/common/historyStorage';
3938
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
40-
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
4139
// tslint:disable-next-line: import-patterns
4240
import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService';
41+
import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
4342

4443
//#region Download
4544

@@ -614,63 +613,18 @@ registerSingleton(IWindowService, SimpleWindowService);
614613

615614
//#region ExtensionHostDebugService
616615

617-
export class SimpleExtensionHostDebugService implements IExtensionHostDebugService {
618-
_serviceBrand: any;
619-
620-
private channel: IChannel;
616+
export class SimpleExtensionHostDebugService extends ExtensionHostDebugChannelClient {
621617

622618
constructor(
623-
@IRemoteAgentService private remoteAgentService: IRemoteAgentService
619+
@IRemoteAgentService remoteAgentService: IRemoteAgentService
624620
) {
625-
const connection = this.remoteAgentService.getConnection();
626-
if (connection) {
627-
this.channel = connection.getChannel('extensionhostdebugservice');
628-
}
629-
}
630-
631-
reload(sessionId: string): void {
632-
if (this.channel) {
633-
this.channel.call('reload', [sessionId]);
634-
}
635-
}
636-
get onReload(): Event<IReloadSessionEvent> {
637-
return this.channel ? this.channel.listen('reload') : Event.None;
638-
}
639-
640-
close(sessionId: string): void {
641-
if (this.channel) {
642-
this.channel.call('close', [sessionId]);
643-
}
644-
}
645-
get onClose(): Event<ICloseSessionEvent> {
646-
return this.channel ? this.channel.listen('close') : Event.None;
647-
}
648-
649-
attachSession(sessionId: string, port: number, subId?: string): void {
650-
if (this.channel) {
651-
this.channel.call('attach', [sessionId, port, subId]);
652-
}
653-
}
654-
get onAttachSession(): Event<IAttachSessionEvent> {
655-
return this.channel ? this.channel.listen('attach') : Event.None;
656-
}
621+
const connection = remoteAgentService.getConnection();
657622

658-
logToSession(sessionId: string, log: IRemoteConsoleLog): void {
659-
if (this.channel) {
660-
this.channel.call('log', [sessionId, log]);
623+
if (!connection) {
624+
throw new Error('Missing agent connection');
661625
}
662-
}
663-
get onLogToSession(): Event<ILogToSessionEvent> {
664-
return this.channel ? this.channel.listen('log') : Event.None;
665-
}
666626

667-
terminateSession(sessionId: string, subId?: string): void {
668-
if (this.channel) {
669-
this.channel.call('terminate', [sessionId, subId]);
670-
}
671-
}
672-
get onTerminateSession(): Event<ITerminateSessionEvent> {
673-
return this.channel ? this.channel.listen('terminate') : Event.None;
627+
super(connection.getChannel(ExtensionHostDebugBroadcastChannel.ChannelName));
674628
}
675629
}
676630
registerSingleton(IExtensionHostDebugService, SimpleExtensionHostDebugService);

src/vs/workbench/contrib/debug/browser/debugService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { IDebugService, State, IDebugSession, CONTEXT_DEBUG_TYPE, CONTEXT_DEBUG_
4545
import { isExtensionHostDebugging } from 'vs/workbench/contrib/debug/common/debugUtils';
4646
import { isErrorWithActions, createErrorWithActions } from 'vs/base/common/errorsWithActions';
4747
import { RunOnceScheduler } from 'vs/base/common/async';
48-
import { IExtensionHostDebugService } from 'vs/workbench/services/extensions/common/extensionHostDebug';
48+
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
4949
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
5050

5151
const DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';

src/vs/workbench/services/extensions/common/remoteExtensionHostClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
2424
import { PersistentProtocol } from 'vs/base/parts/ipc/common/ipc.net';
2525
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
2626
import { VSBuffer } from 'vs/base/common/buffer';
27-
import { IExtensionHostDebugService } from 'vs/workbench/services/extensions/common/extensionHostDebug';
27+
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
2828
import { IProductService } from 'vs/platform/product/common/product';
2929
import { ISignService } from 'vs/platform/sign/common/sign';
3030

src/vs/workbench/services/extensions/electron-browser/extensionHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { withNullAsUndefined } from 'vs/base/common/types';
3535
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
3636
import { parseExtensionDevOptions } from '../common/extensionDevOptions';
3737
import { VSBuffer } from 'vs/base/common/buffer';
38-
import { IExtensionHostDebugService } from 'vs/workbench/services/extensions/common/extensionHostDebug';
38+
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
3939
import { IExtensionHostStarter } from 'vs/workbench/services/extensions/common/extensions';
4040
import { isEqualOrParent } from 'vs/base/common/resources';
4141

src/vs/workbench/services/extensions/electron-browser/extensionHostDebugService.ts

Lines changed: 6 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -3,128 +3,17 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Event, Emitter } from 'vs/base/common/event';
7-
import { IWindowService } from 'vs/platform/windows/common/windows';
86
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';
1210

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 {
4412

4513
constructor(
46-
@IWindowService readonly windowService: IWindowService,
14+
@IMainProcessService readonly windowService: IMainProcessService,
4715
) {
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));
12817
}
12918
}
13019

0 commit comments

Comments
 (0)