From 7072bf1e83748b0abb7a23e0f2c91103964bc987 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 2 Jul 2019 10:34:03 -0500 Subject: [PATCH] Use new URI transformer everywhere --- channel.ts | 44 ++++++++++++++++++----------- connection.ts | 3 +- server.ts | 14 +++++---- transformer.js => uriTransformer.js | 4 +-- 4 files changed, 40 insertions(+), 25 deletions(-) rename transformer.js => uriTransformer.js (80%) diff --git a/channel.ts b/channel.ts index 9b830d4c..f88321c1 100644 --- a/channel.ts +++ b/channel.ts @@ -1,11 +1,12 @@ import * as path from "path"; +import { getPathFromAmdModule } from "vs/base/common/amd"; import { VSBuffer } from "vs/base/common/buffer"; import { Emitter, Event } from "vs/base/common/event"; import { IDisposable } from "vs/base/common/lifecycle"; -import { Schemas } from "vs/base/common/network"; import { OS } from "vs/base/common/platform"; import { URI, UriComponents } from "vs/base/common/uri"; +import { URITransformer, IRawURITransformer, transformOutgoingURIs } from "vs/base/common/uriIpc"; import { IServerChannel } from "vs/base/parts/ipc/common/ipc"; import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService"; import { IEnvironmentService } from "vs/platform/environment/common/environment"; @@ -47,7 +48,7 @@ export class FileProviderChannel implements IServerChannel { this.provider = new DiskFileSystemProvider(this.logService); } - public listen(_: unknown, event: string, args?: any): Event { + public listen(context: any, event: string, args?: any): Event { switch (event) { // This is where the actual file changes are sent. The watch method just // adds things that will fire here. That means we have to split up @@ -61,10 +62,11 @@ export class FileProviderChannel implements IServerChannel { onFirstListenerAdd: () => { const provider = new Watcher(this.logService); this.watchers.set(session, provider); + const transformer = getUriTransformer(context.remoteAuthority); provider.onDidChangeFile((events) => { emitter.fire(events.map((event) => ({ ...event, - resource: event.resource.with({ scheme: Schemas.vscodeRemote }), + resource: transformer.transformOutgoing(event.resource), }))); }); provider.onDidErrorOccur((event) => emitter.fire(event)); @@ -157,13 +159,17 @@ export class FileProviderChannel implements IServerChannel { export class ExtensionEnvironmentChannel implements IServerChannel { public constructor(private readonly environment: IEnvironmentService) {} - public listen(_context: any, event: string): Event { + public listen(_: unknown, event: string): Event { throw new Error(`Invalid listen "${event}"`); } - public call(_: unknown, command: string, _args?: any): Promise { + public async call(context: any, command: string, _args?: any): Promise { switch (command) { - case "getEnvironmentData": return this.getEnvironmentData(); + case "getEnvironmentData": + return transformOutgoingURIs( + await this.getEnvironmentData(), + getUriTransformer(context.remoteAuthority), + ); case "getDiagnosticInfo": return this.getDiagnosticInfo(); case "disableTelemetry": return this.disableTelemetry(); } @@ -171,18 +177,16 @@ export class ExtensionEnvironmentChannel implements IServerChannel { } private async getEnvironmentData(): Promise { - // TODO: this `with` stuff feels a bit jank. - // Maybe it should already come in like this instead. return { pid: process.pid, - appRoot: URI.file(this.environment.appRoot).with({ scheme: Schemas.vscodeRemote }), - appSettingsHome: this.environment.appSettingsHome.with({ scheme: Schemas.vscodeRemote }), - settingsPath: this.environment.machineSettingsHome.with({ scheme: Schemas.vscodeRemote }), - logsPath: URI.file(this.environment.logsPath).with({ scheme: Schemas.vscodeRemote }), - extensionsPath: URI.file(this.environment.extensionsPath).with({ scheme: Schemas.vscodeRemote }), - extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")).with({ scheme: Schemas.vscodeRemote }), // TODO - globalStorageHome: URI.file(this.environment.globalStorageHome).with({ scheme: Schemas.vscodeRemote }), - userHome: URI.file(this.environment.userHome).with({ scheme: Schemas.vscodeRemote }), + appRoot: URI.file(this.environment.appRoot), + appSettingsHome: this.environment.appSettingsHome, + settingsPath: this.environment.machineSettingsHome, + logsPath: URI.file(this.environment.logsPath), + extensionsPath: URI.file(this.environment.extensionsPath), + extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")), // TODO + globalStorageHome: URI.file(this.environment.globalStorageHome), + userHome: URI.file(this.environment.userHome), extensions: [], // TODO os: OS, }; @@ -196,3 +200,11 @@ export class ExtensionEnvironmentChannel implements IServerChannel { throw new Error("not implemented"); } } + +export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/uriTransformer"); + +export const getUriTransformer = (remoteAuthority: string): URITransformer => { + const rawURITransformerFactory = require.__$__nodeRequire(uriTransformerPath); + const rawURITransformer = rawURITransformerFactory(remoteAuthority); + return new URITransformer(rawURITransformer); +}; diff --git a/connection.ts b/connection.ts index 7a6d7d4d..8d1d7c2e 100644 --- a/connection.ts +++ b/connection.ts @@ -6,6 +6,7 @@ import { Emitter } from "vs/base/common/event"; import { ISocket } from "vs/base/parts/ipc/common/ipc.net"; import { NodeSocket, WebSocketNodeSocket } from "vs/base/parts/ipc/node/ipc.net"; import { ILogService } from "vs/platform/log/common/log"; +import { uriTransformerPath } from "vs/server/channel"; import { IExtHostReadyMessage, IExtHostSocketMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol"; import { Protocol } from "vs/server/protocol"; @@ -125,7 +126,7 @@ export class ExtensionHostConnection extends Connection { getPathFromAmdModule(require, "bootstrap-fork"), [ "--type=extensionHost", - `--uriTransformerPath=${getPathFromAmdModule(require, "vs/server/transformer")}` + `--uriTransformerPath=${uriTransformerPath}` ], { env: { diff --git a/server.ts b/server.ts index 02951a93..d774d7cf 100644 --- a/server.ts +++ b/server.ts @@ -7,9 +7,8 @@ import * as url from "url"; import { Emitter } from "vs/base/common/event"; import { getMediaMime } from "vs/base/common/mime"; -import { Schemas } from "vs/base/common/network"; import { extname } from "vs/base/common/path"; -import { URI } from "vs/base/common/uri"; +import { UriComponents, URI } from "vs/base/common/uri"; import { IPCServer, ClientConnectionEvent } from "vs/base/parts/ipc/common/ipc"; import { validatePaths } from "vs/code/node/paths"; import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper"; @@ -26,7 +25,7 @@ import { RemoteExtensionLogFileName } from "vs/workbench/services/remote/common/ import { IWorkbenchConstructionOptions } from "vs/workbench/workbench.web.api"; import { Connection, ManagementConnection, ExtensionHostConnection } from "vs/server/connection"; -import { ExtensionEnvironmentChannel, FileProviderChannel } from "vs/server/channel"; +import { ExtensionEnvironmentChannel, FileProviderChannel, getUriTransformer } from "vs/server/channel"; import { Protocol } from "vs/server/protocol"; export enum HttpCode { @@ -37,7 +36,7 @@ export enum HttpCode { export interface Options { WORKBENCH_WEB_CONGIGURATION: IWorkbenchConstructionOptions; - REMOTE_USER_DATA_URI: URI; + REMOTE_USER_DATA_URI: UriComponents | URI; PRODUCT_CONFIGURATION: IProductConfiguration | null; CONNECTION_AUTH_TOKEN: string; } @@ -149,11 +148,14 @@ export class Server { let html = await util.promisify(fs.readFile)(htmlPath, "utf8"); + const remoteAuthority = request.headers.host as string; + const transformer = getUriTransformer(remoteAuthority); + const options: Options = { WORKBENCH_WEB_CONGIGURATION: { - remoteAuthority: request.headers.host as string, + remoteAuthority, }, - REMOTE_USER_DATA_URI: this.environmentService.webUserDataHome.with({ scheme: Schemas.vscodeRemote }), + REMOTE_USER_DATA_URI: transformer.transformOutgoing(this.environmentService.webUserDataHome), PRODUCT_CONFIGURATION: null, CONNECTION_AUTH_TOKEN: "", }; diff --git a/transformer.js b/uriTransformer.js similarity index 80% rename from transformer.js rename to uriTransformer.js index 73d24601..ce582306 100644 --- a/transformer.js +++ b/uriTransformer.js @@ -5,14 +5,14 @@ module.exports = (remoteAuthority) => { transformIncoming: (uri) => { switch (uri.scheme) { case "vscode-remote": return { scheme: "file", path: uri.path }; - case "file ": return { scheme: "vscode-local", path: uri.path }; + case "file": return { scheme: "vscode-local", path: uri.path }; default: return uri; } }, transformOutgoing: (uri) => { switch (uri.scheme) { case "vscode-local": return { scheme: "file", path: uri.path }; - case "file ": return { scheme: "vscode-remote", authority: remoteAuthority, path: uri.path }; + case "file": return { scheme: "vscode-remote", authority: remoteAuthority, path: uri.path }; default: return uri; } },