Skip to content

Commit 7072bf1

Browse files
committed
Use new URI transformer everywhere
1 parent 4e0a6d2 commit 7072bf1

4 files changed

Lines changed: 40 additions & 25 deletions

File tree

channel.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as path from "path";
22

3+
import { getPathFromAmdModule } from "vs/base/common/amd";
34
import { VSBuffer } from "vs/base/common/buffer";
45
import { Emitter, Event } from "vs/base/common/event";
56
import { IDisposable } from "vs/base/common/lifecycle";
6-
import { Schemas } from "vs/base/common/network";
77
import { OS } from "vs/base/common/platform";
88
import { URI, UriComponents } from "vs/base/common/uri";
9+
import { URITransformer, IRawURITransformer, transformOutgoingURIs } from "vs/base/common/uriIpc";
910
import { IServerChannel } from "vs/base/parts/ipc/common/ipc";
1011
import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService";
1112
import { IEnvironmentService } from "vs/platform/environment/common/environment";
@@ -47,7 +48,7 @@ export class FileProviderChannel implements IServerChannel {
4748
this.provider = new DiskFileSystemProvider(this.logService);
4849
}
4950

50-
public listen(_: unknown, event: string, args?: any): Event<any> {
51+
public listen(context: any, event: string, args?: any): Event<any> {
5152
switch (event) {
5253
// This is where the actual file changes are sent. The watch method just
5354
// adds things that will fire here. That means we have to split up
@@ -61,10 +62,11 @@ export class FileProviderChannel implements IServerChannel {
6162
onFirstListenerAdd: () => {
6263
const provider = new Watcher(this.logService);
6364
this.watchers.set(session, provider);
65+
const transformer = getUriTransformer(context.remoteAuthority);
6466
provider.onDidChangeFile((events) => {
6567
emitter.fire(events.map((event) => ({
6668
...event,
67-
resource: event.resource.with({ scheme: Schemas.vscodeRemote }),
69+
resource: transformer.transformOutgoing(event.resource),
6870
})));
6971
});
7072
provider.onDidErrorOccur((event) => emitter.fire(event));
@@ -157,32 +159,34 @@ export class FileProviderChannel implements IServerChannel {
157159
export class ExtensionEnvironmentChannel implements IServerChannel {
158160
public constructor(private readonly environment: IEnvironmentService) {}
159161

160-
public listen(_context: any, event: string): Event<any> {
162+
public listen(_: unknown, event: string): Event<any> {
161163
throw new Error(`Invalid listen "${event}"`);
162164
}
163165

164-
public call(_: unknown, command: string, _args?: any): Promise<any> {
166+
public async call(context: any, command: string, _args?: any): Promise<any> {
165167
switch (command) {
166-
case "getEnvironmentData": return this.getEnvironmentData();
168+
case "getEnvironmentData":
169+
return transformOutgoingURIs(
170+
await this.getEnvironmentData(),
171+
getUriTransformer(context.remoteAuthority),
172+
);
167173
case "getDiagnosticInfo": return this.getDiagnosticInfo();
168174
case "disableTelemetry": return this.disableTelemetry();
169175
}
170176
throw new Error(`Invalid call "${command}"`);
171177
}
172178

173179
private async getEnvironmentData(): Promise<IRemoteAgentEnvironment> {
174-
// TODO: this `with` stuff feels a bit jank.
175-
// Maybe it should already come in like this instead.
176180
return {
177181
pid: process.pid,
178-
appRoot: URI.file(this.environment.appRoot).with({ scheme: Schemas.vscodeRemote }),
179-
appSettingsHome: this.environment.appSettingsHome.with({ scheme: Schemas.vscodeRemote }),
180-
settingsPath: this.environment.machineSettingsHome.with({ scheme: Schemas.vscodeRemote }),
181-
logsPath: URI.file(this.environment.logsPath).with({ scheme: Schemas.vscodeRemote }),
182-
extensionsPath: URI.file(this.environment.extensionsPath).with({ scheme: Schemas.vscodeRemote }),
183-
extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")).with({ scheme: Schemas.vscodeRemote }), // TODO
184-
globalStorageHome: URI.file(this.environment.globalStorageHome).with({ scheme: Schemas.vscodeRemote }),
185-
userHome: URI.file(this.environment.userHome).with({ scheme: Schemas.vscodeRemote }),
182+
appRoot: URI.file(this.environment.appRoot),
183+
appSettingsHome: this.environment.appSettingsHome,
184+
settingsPath: this.environment.machineSettingsHome,
185+
logsPath: URI.file(this.environment.logsPath),
186+
extensionsPath: URI.file(this.environment.extensionsPath),
187+
extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")), // TODO
188+
globalStorageHome: URI.file(this.environment.globalStorageHome),
189+
userHome: URI.file(this.environment.userHome),
186190
extensions: [], // TODO
187191
os: OS,
188192
};
@@ -196,3 +200,11 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
196200
throw new Error("not implemented");
197201
}
198202
}
203+
204+
export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/uriTransformer");
205+
206+
export const getUriTransformer = (remoteAuthority: string): URITransformer => {
207+
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath);
208+
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
209+
return new URITransformer(rawURITransformer);
210+
};

connection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Emitter } from "vs/base/common/event";
66
import { ISocket } from "vs/base/parts/ipc/common/ipc.net";
77
import { NodeSocket, WebSocketNodeSocket } from "vs/base/parts/ipc/node/ipc.net";
88
import { ILogService } from "vs/platform/log/common/log";
9+
import { uriTransformerPath } from "vs/server/channel";
910
import { IExtHostReadyMessage, IExtHostSocketMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol";
1011

1112
import { Protocol } from "vs/server/protocol";
@@ -125,7 +126,7 @@ export class ExtensionHostConnection extends Connection {
125126
getPathFromAmdModule(require, "bootstrap-fork"),
126127
[
127128
"--type=extensionHost",
128-
`--uriTransformerPath=${getPathFromAmdModule(require, "vs/server/transformer")}`
129+
`--uriTransformerPath=${uriTransformerPath}`
129130
],
130131
{
131132
env: {

server.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import * as url from "url";
77

88
import { Emitter } from "vs/base/common/event";
99
import { getMediaMime } from "vs/base/common/mime";
10-
import { Schemas } from "vs/base/common/network";
1110
import { extname } from "vs/base/common/path";
12-
import { URI } from "vs/base/common/uri";
11+
import { UriComponents, URI } from "vs/base/common/uri";
1312
import { IPCServer, ClientConnectionEvent } from "vs/base/parts/ipc/common/ipc";
1413
import { validatePaths } from "vs/code/node/paths";
1514
import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper";
@@ -26,7 +25,7 @@ import { RemoteExtensionLogFileName } from "vs/workbench/services/remote/common/
2625
import { IWorkbenchConstructionOptions } from "vs/workbench/workbench.web.api";
2726

2827
import { Connection, ManagementConnection, ExtensionHostConnection } from "vs/server/connection";
29-
import { ExtensionEnvironmentChannel, FileProviderChannel } from "vs/server/channel";
28+
import { ExtensionEnvironmentChannel, FileProviderChannel, getUriTransformer } from "vs/server/channel";
3029
import { Protocol } from "vs/server/protocol";
3130

3231
export enum HttpCode {
@@ -37,7 +36,7 @@ export enum HttpCode {
3736

3837
export interface Options {
3938
WORKBENCH_WEB_CONGIGURATION: IWorkbenchConstructionOptions;
40-
REMOTE_USER_DATA_URI: URI;
39+
REMOTE_USER_DATA_URI: UriComponents | URI;
4140
PRODUCT_CONFIGURATION: IProductConfiguration | null;
4241
CONNECTION_AUTH_TOKEN: string;
4342
}
@@ -149,11 +148,14 @@ export class Server {
149148

150149
let html = await util.promisify(fs.readFile)(htmlPath, "utf8");
151150

151+
const remoteAuthority = request.headers.host as string;
152+
const transformer = getUriTransformer(remoteAuthority);
153+
152154
const options: Options = {
153155
WORKBENCH_WEB_CONGIGURATION: {
154-
remoteAuthority: request.headers.host as string,
156+
remoteAuthority,
155157
},
156-
REMOTE_USER_DATA_URI: this.environmentService.webUserDataHome.with({ scheme: Schemas.vscodeRemote }),
158+
REMOTE_USER_DATA_URI: transformer.transformOutgoing(this.environmentService.webUserDataHome),
157159
PRODUCT_CONFIGURATION: null,
158160
CONNECTION_AUTH_TOKEN: "",
159161
};

transformer.js renamed to uriTransformer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ module.exports = (remoteAuthority) => {
55
transformIncoming: (uri) => {
66
switch (uri.scheme) {
77
case "vscode-remote": return { scheme: "file", path: uri.path };
8-
case "file ": return { scheme: "vscode-local", path: uri.path };
8+
case "file": return { scheme: "vscode-local", path: uri.path };
99
default: return uri;
1010
}
1111
},
1212
transformOutgoing: (uri) => {
1313
switch (uri.scheme) {
1414
case "vscode-local": return { scheme: "file", path: uri.path };
15-
case "file ": return { scheme: "vscode-remote", authority: remoteAuthority, path: uri.path };
15+
case "file": return { scheme: "vscode-remote", authority: remoteAuthority, path: uri.path };
1616
default: return uri;
1717
}
1818
},

0 commit comments

Comments
 (0)