Use new URI transformer everywhere

This commit is contained in:
Asher 2019-07-02 10:34:03 -05:00
parent 4e0a6d2941
commit 7072bf1e83
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
4 changed files with 40 additions and 25 deletions

View File

@ -1,11 +1,12 @@
import * as path from "path"; import * as path from "path";
import { getPathFromAmdModule } from "vs/base/common/amd";
import { VSBuffer } from "vs/base/common/buffer"; import { VSBuffer } from "vs/base/common/buffer";
import { Emitter, Event } from "vs/base/common/event"; import { Emitter, Event } from "vs/base/common/event";
import { IDisposable } from "vs/base/common/lifecycle"; import { IDisposable } from "vs/base/common/lifecycle";
import { Schemas } from "vs/base/common/network";
import { OS } from "vs/base/common/platform"; import { OS } from "vs/base/common/platform";
import { URI, UriComponents } from "vs/base/common/uri"; 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 { IServerChannel } from "vs/base/parts/ipc/common/ipc";
import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService"; import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService";
import { IEnvironmentService } from "vs/platform/environment/common/environment"; import { IEnvironmentService } from "vs/platform/environment/common/environment";
@ -47,7 +48,7 @@ export class FileProviderChannel implements IServerChannel {
this.provider = new DiskFileSystemProvider(this.logService); this.provider = new DiskFileSystemProvider(this.logService);
} }
public listen(_: unknown, event: string, args?: any): Event<any> { public listen(context: any, event: string, args?: any): Event<any> {
switch (event) { switch (event) {
// This is where the actual file changes are sent. The watch method just // 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 // adds things that will fire here. That means we have to split up
@ -61,10 +62,11 @@ export class FileProviderChannel implements IServerChannel {
onFirstListenerAdd: () => { onFirstListenerAdd: () => {
const provider = new Watcher(this.logService); const provider = new Watcher(this.logService);
this.watchers.set(session, provider); this.watchers.set(session, provider);
const transformer = getUriTransformer(context.remoteAuthority);
provider.onDidChangeFile((events) => { provider.onDidChangeFile((events) => {
emitter.fire(events.map((event) => ({ emitter.fire(events.map((event) => ({
...event, ...event,
resource: event.resource.with({ scheme: Schemas.vscodeRemote }), resource: transformer.transformOutgoing(event.resource),
}))); })));
}); });
provider.onDidErrorOccur((event) => emitter.fire(event)); provider.onDidErrorOccur((event) => emitter.fire(event));
@ -157,13 +159,17 @@ export class FileProviderChannel implements IServerChannel {
export class ExtensionEnvironmentChannel implements IServerChannel { export class ExtensionEnvironmentChannel implements IServerChannel {
public constructor(private readonly environment: IEnvironmentService) {} public constructor(private readonly environment: IEnvironmentService) {}
public listen(_context: any, event: string): Event<any> { public listen(_: unknown, event: string): Event<any> {
throw new Error(`Invalid listen "${event}"`); throw new Error(`Invalid listen "${event}"`);
} }
public call(_: unknown, command: string, _args?: any): Promise<any> { public async call(context: any, command: string, _args?: any): Promise<any> {
switch (command) { switch (command) {
case "getEnvironmentData": return this.getEnvironmentData(); case "getEnvironmentData":
return transformOutgoingURIs(
await this.getEnvironmentData(),
getUriTransformer(context.remoteAuthority),
);
case "getDiagnosticInfo": return this.getDiagnosticInfo(); case "getDiagnosticInfo": return this.getDiagnosticInfo();
case "disableTelemetry": return this.disableTelemetry(); case "disableTelemetry": return this.disableTelemetry();
} }
@ -171,18 +177,16 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
} }
private async getEnvironmentData(): Promise<IRemoteAgentEnvironment> { private async getEnvironmentData(): Promise<IRemoteAgentEnvironment> {
// TODO: this `with` stuff feels a bit jank.
// Maybe it should already come in like this instead.
return { return {
pid: process.pid, pid: process.pid,
appRoot: URI.file(this.environment.appRoot).with({ scheme: Schemas.vscodeRemote }), appRoot: URI.file(this.environment.appRoot),
appSettingsHome: this.environment.appSettingsHome.with({ scheme: Schemas.vscodeRemote }), appSettingsHome: this.environment.appSettingsHome,
settingsPath: this.environment.machineSettingsHome.with({ scheme: Schemas.vscodeRemote }), settingsPath: this.environment.machineSettingsHome,
logsPath: URI.file(this.environment.logsPath).with({ scheme: Schemas.vscodeRemote }), logsPath: URI.file(this.environment.logsPath),
extensionsPath: URI.file(this.environment.extensionsPath).with({ scheme: Schemas.vscodeRemote }), extensionsPath: URI.file(this.environment.extensionsPath),
extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")).with({ scheme: Schemas.vscodeRemote }), // TODO extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")), // TODO
globalStorageHome: URI.file(this.environment.globalStorageHome).with({ scheme: Schemas.vscodeRemote }), globalStorageHome: URI.file(this.environment.globalStorageHome),
userHome: URI.file(this.environment.userHome).with({ scheme: Schemas.vscodeRemote }), userHome: URI.file(this.environment.userHome),
extensions: [], // TODO extensions: [], // TODO
os: OS, os: OS,
}; };
@ -196,3 +200,11 @@ export class ExtensionEnvironmentChannel implements IServerChannel {
throw new Error("not implemented"); throw new Error("not implemented");
} }
} }
export const uriTransformerPath = getPathFromAmdModule(require, "vs/server/uriTransformer");
export const getUriTransformer = (remoteAuthority: string): URITransformer => {
const rawURITransformerFactory = <any>require.__$__nodeRequire(uriTransformerPath);
const rawURITransformer = <IRawURITransformer>rawURITransformerFactory(remoteAuthority);
return new URITransformer(rawURITransformer);
};

View File

@ -6,6 +6,7 @@ import { Emitter } from "vs/base/common/event";
import { ISocket } from "vs/base/parts/ipc/common/ipc.net"; import { ISocket } from "vs/base/parts/ipc/common/ipc.net";
import { NodeSocket, WebSocketNodeSocket } from "vs/base/parts/ipc/node/ipc.net"; import { NodeSocket, WebSocketNodeSocket } from "vs/base/parts/ipc/node/ipc.net";
import { ILogService } from "vs/platform/log/common/log"; 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 { IExtHostReadyMessage, IExtHostSocketMessage } from "vs/workbench/services/extensions/common/extensionHostProtocol";
import { Protocol } from "vs/server/protocol"; import { Protocol } from "vs/server/protocol";
@ -125,7 +126,7 @@ export class ExtensionHostConnection extends Connection {
getPathFromAmdModule(require, "bootstrap-fork"), getPathFromAmdModule(require, "bootstrap-fork"),
[ [
"--type=extensionHost", "--type=extensionHost",
`--uriTransformerPath=${getPathFromAmdModule(require, "vs/server/transformer")}` `--uriTransformerPath=${uriTransformerPath}`
], ],
{ {
env: { env: {

View File

@ -7,9 +7,8 @@ import * as url from "url";
import { Emitter } from "vs/base/common/event"; import { Emitter } from "vs/base/common/event";
import { getMediaMime } from "vs/base/common/mime"; import { getMediaMime } from "vs/base/common/mime";
import { Schemas } from "vs/base/common/network";
import { extname } from "vs/base/common/path"; 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 { IPCServer, ClientConnectionEvent } from "vs/base/parts/ipc/common/ipc";
import { validatePaths } from "vs/code/node/paths"; import { validatePaths } from "vs/code/node/paths";
import { parseMainProcessArgv } from "vs/platform/environment/node/argvHelper"; 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 { IWorkbenchConstructionOptions } from "vs/workbench/workbench.web.api";
import { Connection, ManagementConnection, ExtensionHostConnection } from "vs/server/connection"; 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"; import { Protocol } from "vs/server/protocol";
export enum HttpCode { export enum HttpCode {
@ -37,7 +36,7 @@ export enum HttpCode {
export interface Options { export interface Options {
WORKBENCH_WEB_CONGIGURATION: IWorkbenchConstructionOptions; WORKBENCH_WEB_CONGIGURATION: IWorkbenchConstructionOptions;
REMOTE_USER_DATA_URI: URI; REMOTE_USER_DATA_URI: UriComponents | URI;
PRODUCT_CONFIGURATION: IProductConfiguration | null; PRODUCT_CONFIGURATION: IProductConfiguration | null;
CONNECTION_AUTH_TOKEN: string; CONNECTION_AUTH_TOKEN: string;
} }
@ -149,11 +148,14 @@ export class Server {
let html = await util.promisify(fs.readFile)(htmlPath, "utf8"); let html = await util.promisify(fs.readFile)(htmlPath, "utf8");
const remoteAuthority = request.headers.host as string;
const transformer = getUriTransformer(remoteAuthority);
const options: Options = { const options: Options = {
WORKBENCH_WEB_CONGIGURATION: { 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, PRODUCT_CONFIGURATION: null,
CONNECTION_AUTH_TOKEN: "", CONNECTION_AUTH_TOKEN: "",
}; };