messagePortProtocolServer.ts ×13

Frontier kind: Code frontier

unlabeled · c_13fc0f2a15ba

80 tests · 6603 LOC · 31 files · introduces 0 tests · 44 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges44 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
683 ranges6603 lines · 31 files · Browse complete extent
All tests (intent)
80 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 44 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/messagePortProtocolServer.ts 44 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- messagePortProtocolServer.ts
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 { IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
9 > import { JSON_RPC_PARSE_ERROR, type AhpServerNotification, type JsonRpcNotification, type JsonRpcParseErrorResponse, type JsonRpcRequest, type JsonRpcResponse, type ProtocolMessage } from '../common/state/sessionProtocol.js';
10 > import type { IProtocolServer, IProtocolTransport } from '../common/state/sessionTransport.js';
11 >
12 > /**
13 > * Adapts MessagePort IPC clients to Agent Host Protocol transports.
14 > *
15 > * Consumers must call {@link closeClient} when a UtilityProcessServer client
16 > * connection disappears.
17 > */
18 > export class MessagePortProtocolServer<TContext> extends Disposable implements IProtocolServer, IServerChannel<TContext> {
19
20 private readonly _onConnection = this._register(new Emitter<IProtocolTransport>());
24
25 private readonly _transports = new Map<TContext, MessagePortProtocolTransport>();
27 > listen<T>(ctx: TContext, event: string): Event<T> {
28 switch (event) {
29 case 'frame':
35 throw new Error(`Invalid listen: ${event}`);
36 }
38 > async call<T>(ctx: TContext, command: string, arg?: unknown): Promise<T> {
39 switch (command) {
40 case 'connect': {
65 throw new Error(`Invalid call: ${command}`);
66 }
68 > /**
69 > * Closes a client's transport after its owning IPC connection disappears.
70 > */
71 > closeClient(ctx: TContext): void {
72 const transport = this._transports.get(ctx);
73 if (!transport) {
78 transport.dispose();
79 }
81 > override dispose(): void {
82 const transports = [...this._transports.values()];
83 this._transports.clear();
87 super.dispose();
88 }
90 > private _getOrCreateTransport(ctx: TContext): MessagePortProtocolTransport {
91 if (this._store.isDisposed) {
92 throw new Error('MessagePortProtocolServer is disposed');
108 return transport;
109 }
111 >
112 class MessagePortProtocolTransport extends Disposable implements IProtocolTransport {
113
123 private _isConnected = false;
124 private _isClosed = false;
126 > get isConnected(): boolean {
127 return this._isConnected && !this._isClosed;
128 }
130 > connect(): boolean {
131 if (this._isClosed || this._isConnected) {
132 return false;
136 return true;
137 }
139 > acceptFrame(frame: string): void {
140 try {
141 this._onMessage.fire(JSON.parse(frame) as ProtocolMessage);
144 }
145 }
147 > send(message: ProtocolMessage | AhpServerNotification | JsonRpcNotification | JsonRpcParseErrorResponse | JsonRpcResponse | JsonRpcRequest): void {
148 if (!this.isConnected) {
149 return;
152 this._onFrame.fire(JSON.stringify(message));
153 }
155 > override dispose(): void {
156 if (this._isClosed) {
157 return;