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

85 LOC · 83 covered · 2 uncovered · 8 ranges · 195 concepts · 4 introducers · 117 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- proxyIdentifier.ts ×5
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 type { VSBuffer } from '../../../../base/common/buffer.js';
7 > import type { CancellationToken } from '../../../../base/common/cancellation.js';
8 >
9 > export interface IRPCProtocol {
10 > /**
11 > * Returns a proxy to an object addressable/named in the extension host process or in the renderer process.
12 > */
13 > getProxy<T>(identifier: ProxyIdentifier<T>): Proxied<T>;
14 >
15 > /**
16 > * Register manually created instance.
17 > */
18 > set<T, R extends T>(identifier: ProxyIdentifier<T>, instance: R): R;
19 >
20 > /**
21 > * Assert these identifiers are already registered via `.set`.
22 > */
23 > assertRegistered(identifiers: ProxyIdentifier<unknown>[]): void;
24 >
25 > /**
26 > * Wait for the write buffer (if applicable) to become empty.
27 > */
28 > drain(): Promise<void>;
29 >
30 > dispose(): void;
31 > }
32 >
33 > export class ProxyIdentifier<T> {
34 > public static count = 0;
35 > _proxyIdentifierBrand: void = undefined;
36 >
37 > public readonly sid: string;
38 > public readonly nid: number;
39 >
40 > constructor(sid: string) {
41 > this.sid = sid; proxyIdentifier.ts ×1
42 > this.nid = (++ProxyIdentifier.count);
43 > }
45 >
46 > const identifiers: ProxyIdentifier<unknown>[] = [];
47 >
48 > export function createProxyIdentifier<T>(identifier: string): ProxyIdentifier<T> {
49 > const result = new ProxyIdentifier<T>(identifier); extHost.protocol.ts ×3
50 > identifiers[result.nid] = result;
51 > return result;
52 > }
54 > /**
55 > * Mapped-type that replaces all JSONable-types with their toJSON-result type
56 > */
57 > export type Dto<T> = T extends { toJSON(): infer U }
58 > ? U
59 > : T extends VSBuffer // VSBuffer is understood by rpc-logic
60 > ? T
61 > : T extends CancellationToken // CancellationToken is understood by rpc-logic
62 > ? T
63 > : T extends Function // functions are dropped during JSON-stringify
64 > ? never
65 > : T extends object // recurse
66 > ? { [k in keyof T]: Dto<T[k]>; }
67 > : T;
68 >
69 > export type Proxied<T> = { [K in keyof T]: T[K] extends (...args: infer A) => infer R
70 > ? (...args: { [K in keyof A]: Dto<A[K]> }) => Promise<Dto<Awaited<R>>>
71 > : never
72 > };
73 >
74 > export function getStringIdentifierForProxy(nid: number): string {
75 return identifiers[nid].sid;
76 }
78 > /**
79 > * Marks the object as containing buffers that should be serialized more efficiently.
80 > */
81 > export class SerializableObjectWithBuffers<T> {
82 > constructor(
83 > public readonly value: T rpcProtocol.ts ×15
84 > ) { }