-
Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathuriTransformer.ts
51 lines (48 loc) · 1.81 KB
/
uriTransformer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { UriParts, IRawURITransformer, URITransformer, IURITransformer } from 'vs/base/common/uriIpc';
/**
* ```
* --------------------------------
* | UI SIDE | AGENT SIDE |
* |---------------|--------------|
* | vscode-remote | file |
* | file | vscode-local |
* --------------------------------
* ```
*/
function createRawURITransformer(remoteAuthority: string): IRawURITransformer {
return {
transformIncoming: (uri: UriParts): UriParts => {
if (uri.scheme === 'vscode-remote') {
return { scheme: 'file', path: uri.path, query: uri.query, fragment: uri.fragment };
}
if (uri.scheme === 'file') {
return { scheme: 'vscode-local', path: uri.path, query: uri.query, fragment: uri.fragment };
}
return uri;
},
transformOutgoing: (uri: UriParts): UriParts => {
if (uri.scheme === 'file') {
return { scheme: 'vscode-remote', authority: remoteAuthority, path: uri.path, query: uri.query, fragment: uri.fragment };
}
if (uri.scheme === 'vscode-local') {
return { scheme: 'file', path: uri.path, query: uri.query, fragment: uri.fragment };
}
return uri;
},
transformOutgoingScheme: (scheme: string): string => {
if (scheme === 'file') {
return 'vscode-remote';
} else if (scheme === 'vscode-local') {
return 'file';
}
return scheme;
}
};
}
export function createURITransformer(remoteAuthority: string): IURITransformer {
return new URITransformer(createRawURITransformer(remoteAuthority));
}