src/vs/base/common/uriIpc.ts

163 LOC · 65 covered · 98 uncovered · 15 ranges · 598 concepts · 1 introducers · 307 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 > /*--------------------------------------------------------------------------------------------- uriIpc.ts ×15
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 { VSBuffer } from './buffer.js';
7 > import { MarshalledObject } from './marshalling.js';
8 > import { MarshalledId } from './marshallingIds.js';
9 > import { URI, UriComponents } from './uri.js';
10 >
11 > export interface IURITransformer {
12 > transformIncoming(uri: UriComponents): UriComponents;
13 > transformOutgoing(uri: UriComponents): UriComponents;
14 > transformOutgoingURI(uri: URI): URI;
15 > transformOutgoingScheme(scheme: string): string;
16 > }
17 >
18 > export interface UriParts {
19 > scheme: string;
20 > authority?: string;
21 > path?: string;
22 > query?: string;
23 > fragment?: string;
24 > }
25 >
26 > export interface IRawURITransformer {
27 > transformIncoming(uri: UriParts): UriParts;
28 > transformOutgoing(uri: UriParts): UriParts;
29 > transformOutgoingScheme(scheme: string): string;
30 > }
31 >
32 function toJSON(uri: URI): UriComponents {
33 return uri.toJSON();
34 }
36 > export class URITransformer implements IURITransformer {
37 >
38 > private readonly _uriTransformer: IRawURITransformer;
39 >
40 > constructor(uriTransformer: IRawURITransformer) {
41 this._uriTransformer = uriTransformer;
42 }
44 > public transformIncoming(uri: UriComponents): UriComponents {
45 const result = this._uriTransformer.transformIncoming(uri);
46 return (result === uri ? uri : toJSON(URI.from(result)));
47 }
49 > public transformOutgoing(uri: UriComponents): UriComponents {
50 const result = this._uriTransformer.transformOutgoing(uri);
51 return (result === uri ? uri : toJSON(URI.from(result)));
52 }
54 > public transformOutgoingURI(uri: URI): URI {
55 const result = this._uriTransformer.transformOutgoing(uri);
56 return (result === uri ? uri : URI.from(result));
57 }
59 > public transformOutgoingScheme(scheme: string): string {
60 return this._uriTransformer.transformOutgoingScheme(scheme);
61 }
63 >
64 > export const DefaultURITransformer: IURITransformer = new class {
65 > transformIncoming(uri: UriComponents) {
66 return uri;
67 }
69 > transformOutgoing(uri: UriComponents): UriComponents {
70 return uri;
71 }
73 > transformOutgoingURI(uri: URI): URI {
74 return uri;
75 }
77 > transformOutgoingScheme(scheme: string): string {
78 return scheme;
79 }
80 > }; uriIpc.ts ×15
81 >
82 function _transformOutgoingURIs(obj: any, transformer: IURITransformer, depth: number): any {
83
84 if (!obj || depth > 200) {
85 return null;
86 }
87
88 if (typeof obj === 'object') {
89 if (obj instanceof URI) {
90 return transformer.transformOutgoing(obj);
91 }
92
93 // walk object (or array)
94 for (const key in obj) {
95 if (Object.hasOwnProperty.call(obj, key)) {
96 const r = _transformOutgoingURIs(obj[key], transformer, depth + 1);
97 if (r !== null) {
98 obj[key] = r;
99 }
100 }
101 }
102 }
103
104 return null;
105 }
107 > export function transformOutgoingURIs<T>(obj: T, transformer: IURITransformer): T {
108 const result = _transformOutgoingURIs(obj, transformer, 0);
109 if (result === null) {
110 // no change
111 return obj;
112 }
113 return result;
114 }
116 >
117 function _transformIncomingURIs(obj: any, transformer: IURITransformer, revive: boolean, depth: number): any {
118
119 if (!obj || depth > 200) {
120 return null;
121 }
122
123 if (typeof obj === 'object') {
124
125 if ((<MarshalledObject>obj).$mid === MarshalledId.Uri) {
126 return revive ? URI.revive(transformer.transformIncoming(obj)) : transformer.transformIncoming(obj);
127 }
128
129 if (obj instanceof VSBuffer) {
130 return null;
131 }
132
133 // walk object (or array)
134 for (const key in obj) {
135 if (Object.hasOwnProperty.call(obj, key)) {
136 const r = _transformIncomingURIs(obj[key], transformer, revive, depth + 1);
137 if (r !== null) {
138 obj[key] = r;
139 }
140 }
141 }
142 }
143
144 return null;
145 }
147 > export function transformIncomingURIs<T>(obj: T, transformer: IURITransformer): T {
148 const result = _transformIncomingURIs(obj, transformer, false, 0);
149 if (result === null) {
150 // no change
151 return obj;
152 }
153 return result;
154 }
156 > export function transformAndReviveIncomingURIs<T>(obj: T, transformer: IURITransformer): T {
157 const result = _transformIncomingURIs(obj, transformer, true, 0);
158 if (result === null) {
159 // no change
160 return obj;
161 }
162 return result;
163 }