src/vs/platform/remote/common/remoteAuthorityResolver.ts

172 LOC · 135 covered · 37 uncovered · 11 ranges · 230 concepts · 1 introducers · 150 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 > /*--------------------------------------------------------------------------------------------- remoteAuthorityResolver.ts ×11
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 { ErrorNoTelemetry } from '../../../base/common/errors.js';
7 > import { Event } from '../../../base/common/event.js';
8 > import { URI } from '../../../base/common/uri.js';
9 > import { createDecorator } from '../../instantiation/common/instantiation.js';
10 >
11 > export const IRemoteAuthorityResolverService = createDecorator<IRemoteAuthorityResolverService>('remoteAuthorityResolverService');
12 >
13 > export const enum RemoteConnectionType {
14 > WebSocket,
15 > Managed
16 > }
17 >
18 > export class ManagedRemoteConnection {
19 > public readonly type = RemoteConnectionType.Managed;
20 >
21 > constructor(
22 public readonly id: number
23 ) { }
25 > public toString(): string {
26 return `Managed(${this.id})`;
27 }
29 >
30 > export class WebSocketRemoteConnection {
31 > public readonly type = RemoteConnectionType.WebSocket;
32 >
33 > constructor(
34 public readonly host: string,
35 public readonly port: number,
36 ) { }
38 > public toString(): string {
39 return `WebSocket(${this.host}:${this.port})`;
40 }
42 >
43 > export type RemoteConnection = WebSocketRemoteConnection | ManagedRemoteConnection;
44 >
45 > export type RemoteConnectionOfType<T extends RemoteConnectionType> = RemoteConnection & { type: T };
46 >
47 > export interface ResolvedAuthority {
48 > readonly authority: string;
49 > readonly connectTo: RemoteConnection;
50 > readonly connectionToken: string | undefined;
51 > }
52 >
53 > export interface ResolvedOptions {
54 > readonly extensionHostEnv?: { [key: string]: string | null };
55 > readonly isTrusted?: boolean;
56 > readonly authenticationSession?: { id: string; providerId: string };
57 > }
58 >
59 > export interface TunnelDescription {
60 > remoteAddress: { port: number; host: string };
61 > localAddress: { port: number; host: string } | string;
62 > privacy?: string;
63 > protocol?: string;
64 > }
65 > export interface TunnelPrivacy {
66 > themeIcon: string;
67 > id: string;
68 > label: string;
69 > }
70 > export interface TunnelInformation {
71 > environmentTunnels?: TunnelDescription[];
72 > features?: {
73 > elevation: boolean;
74 > public?: boolean;
75 > privacyOptions: TunnelPrivacy[];
76 > protocol: boolean;
77 > };
78 > }
79 >
80 > export interface ResolverResult {
81 > authority: ResolvedAuthority;
82 > options?: ResolvedOptions;
83 > tunnelInformation?: TunnelInformation;
84 > }
85 >
86 > export interface IRemoteConnectionData {
87 > connectTo: RemoteConnection;
88 > connectionToken: string | undefined;
89 > }
90 >
91 > export enum RemoteAuthorityResolverErrorCode {
92 > Unknown = 'Unknown',
93 > NotAvailable = 'NotAvailable',
94 > TemporarilyNotAvailable = 'TemporarilyNotAvailable',
95 > NoResolverFound = 'NoResolverFound',
96 > InvalidAuthority = 'InvalidAuthority'
97 > }
98 >
99 > export class RemoteAuthorityResolverError extends ErrorNoTelemetry {
100 >
101 > public static isNotAvailable(err: any): boolean {
102 return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.NotAvailable;
103 }
105 > public static isTemporarilyNotAvailable(err: any): boolean {
106 return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.TemporarilyNotAvailable;
107 }
109 > public static isNoResolverFound(err: any): err is RemoteAuthorityResolverError {
110 return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.NoResolverFound;
111 }
113 > public static isInvalidAuthority(err: any): boolean {
114 return (err instanceof RemoteAuthorityResolverError) && err._code === RemoteAuthorityResolverErrorCode.InvalidAuthority;
115 }
117 > public static isHandled(err: any): boolean {
118 return (err instanceof RemoteAuthorityResolverError) && err.isHandled;
119 }
121 > public readonly _message: string | undefined;
122 > public readonly _code: RemoteAuthorityResolverErrorCode;
123 > public readonly _detail: unknown;
124 >
125 > public isHandled: boolean;
126 >
127 > constructor(message?: string, code: RemoteAuthorityResolverErrorCode = RemoteAuthorityResolverErrorCode.Unknown, detail?: unknown) {
128 super(message);
129
130 this._message = message;
131 this._code = code;
132 this._detail = detail;
133
134 this.isHandled = (code === RemoteAuthorityResolverErrorCode.NotAvailable) && detail === true;
135
136 // workaround when extending builtin objects and when compiling to ES5, see:
137 // https://github.com/microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
138 Object.setPrototypeOf(this, RemoteAuthorityResolverError.prototype);
139 }
141 >
142 > export interface IRemoteAuthorityResolverService {
143 >
144 > readonly _serviceBrand: undefined;
145 >
146 > readonly onDidChangeConnectionData: Event<void>;
147 >
148 > resolveAuthority(authority: string): Promise<ResolverResult>;
149 > getConnectionData(authority: string): IRemoteConnectionData | null;
150 > /**
151 > * Get the canonical URI for a `vscode-remote://` URI.
152 > *
153 > * **NOTE**: This can throw e.g. in cases where there is no resolver installed for the specific remote authority.
154 > *
155 > * @param uri The `vscode-remote://` URI
156 > */
157 > getCanonicalURI(uri: URI): Promise<URI>;
158 >
159 > _clearResolvedAuthority(authority: string): void;
160 > _setResolvedAuthority(resolvedAuthority: ResolvedAuthority, resolvedOptions?: ResolvedOptions): void;
161 > _setResolvedAuthorityError(authority: string, err: any): void;
162 > _setAuthorityConnectionToken(authority: string, connectionToken: string): void;
163 > _setCanonicalURIProvider(provider: (uri: URI) => Promise<URI>): void;
164 > }
165 >
166 > export function getRemoteAuthorityPrefix(remoteAuthority: string): string {
167 const plusIndex = remoteAuthority.indexOf('+');
168 if (plusIndex === -1) {
169 return remoteAuthority;
170 }
171 return remoteAuthority.substring(0, plusIndex);
172 }