Skip to content

Commit 2afeba7

Browse files
committed
Add resourceUriProvider API
1 parent b5b8c4d commit 2afeba7

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/vs/base/browser/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ export function asDomUri(uri: URI): URI {
11931193
return uri;
11941194
}
11951195
if (Schemas.vscodeRemote === uri.scheme) {
1196-
return RemoteAuthorities.rewrite(uri.authority, uri.path);
1196+
return RemoteAuthorities.rewrite(uri);
11971197
}
11981198
return uri;
11991199
}

src/vs/base/common/network.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { URI } from 'vs/base/common/uri';
6+
import { URI, UriComponents } from 'vs/base/common/uri';
77
import * as platform from 'vs/base/common/platform';
88

99
export namespace Schemas {
@@ -60,18 +60,24 @@ class RemoteAuthoritiesImpl {
6060
private readonly _ports: { [authority: string]: number; };
6161
private readonly _connectionTokens: { [authority: string]: string; };
6262
private _preferredWebSchema: 'http' | 'https';
63+
private _delegate: ((uri: URI) => UriComponents) | null;
6364

6465
constructor() {
6566
this._hosts = Object.create(null);
6667
this._ports = Object.create(null);
6768
this._connectionTokens = Object.create(null);
6869
this._preferredWebSchema = 'http';
70+
this._delegate = null;
6971
}
7072

7173
public setPreferredWebSchema(schema: 'http' | 'https') {
7274
this._preferredWebSchema = schema;
7375
}
7476

77+
public setDelegate(delegate: (uri: URI) => UriComponents): void {
78+
this._delegate = delegate;
79+
}
80+
7581
public set(authority: string, host: string, port: number): void {
7682
this._hosts[authority] = host;
7783
this._ports[authority] = port;
@@ -81,15 +87,20 @@ class RemoteAuthoritiesImpl {
8187
this._connectionTokens[authority] = connectionToken;
8288
}
8389

84-
public rewrite(authority: string, path: string): URI {
90+
public rewrite(uri: URI): URI {
91+
if (this._delegate) {
92+
const result = this._delegate(uri);
93+
return URI.revive(result);
94+
}
95+
const authority = uri.authority;
8596
const host = this._hosts[authority];
8697
const port = this._ports[authority];
8798
const connectionToken = this._connectionTokens[authority];
8899
return URI.from({
89100
scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
90101
authority: `${host}:${port}`,
91102
path: `/vscode-remote-resource`,
92-
query: `path=${encodeURIComponent(path)}&tkn=${encodeURIComponent(connectionToken)}`
103+
query: `path=${encodeURIComponent(uri.path)}&tkn=${encodeURIComponent(connectionToken)}`
93104
});
94105
}
95106
}

src/vs/platform/remote/browser/remoteAuthorityResolverService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
import { ResolvedAuthority, IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/remote/common/remoteAuthorityResolver';
77
import { RemoteAuthorities } from 'vs/base/common/network';
8+
import { URI, UriComponents } from 'vs/base/common/uri';
89

910
export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService {
1011

1112
_serviceBrand: undefined;
1213

13-
constructor() {
14+
constructor(
15+
resourceUriProvider: ((uri: URI) => UriComponents) | undefined
16+
) {
17+
if (resourceUriProvider) {
18+
RemoteAuthorities.setDelegate(resourceUriProvider);
19+
}
1420
}
1521

1622
resolveAuthority(authority: string): Promise<ResolverResult> {

src/vs/workbench/browser/web.main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class CodeRendererMain extends Disposable {
142142
serviceCollection.set(IProductService, productService);
143143

144144
// Remote
145-
const remoteAuthorityResolverService = new RemoteAuthorityResolverService();
145+
const remoteAuthorityResolverService = new RemoteAuthorityResolverService(this.configuration.resourceUriProvider);
146146
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);
147147

148148
// Signing

src/vs/workbench/workbench.web.api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import 'vs/workbench/workbench.web.main';
77
import { main } from 'vs/workbench/browser/web.main';
8-
import { UriComponents } from 'vs/base/common/uri';
8+
import { UriComponents, URI } from 'vs/base/common/uri';
99
import { IFileSystemProvider } from 'vs/platform/files/common/files';
1010
import { IWebSocketFactory } from 'vs/platform/remote/browser/browserSocketFactory';
1111
import { ICredentialsProvider } from 'vs/workbench/services/credentials/browser/credentialsService';
@@ -53,6 +53,11 @@ export interface IWorkbenchConstructionOptions {
5353
*/
5454
webSocketFactory?: IWebSocketFactory;
5555

56+
/**
57+
* A provider for resource URIs.
58+
*/
59+
resourceUriProvider?: (uri: URI) => UriComponents;
60+
5661
/**
5762
* Experimental: Whether to enable the smoke test driver.
5863
*/

0 commit comments

Comments
 (0)