|
| 1 | +import * as path from "path"; |
| 2 | + |
| 3 | +import { Emitter, Event } from "vs/base/common/event"; |
| 4 | +import { OS } from "vs/base/common/platform"; |
| 5 | +import { URI } from "vs/base/common/uri"; |
| 6 | +import { IServerChannel } from "vs/base/parts/ipc/common/ipc"; |
| 7 | +import { IDiagnosticInfo } from "vs/platform/diagnostics/common/diagnosticsService"; |
| 8 | +import { IEnvironmentService } from "vs/platform/environment/common/environment"; |
| 9 | +import { FileDeleteOptions, FileOverwriteOptions, FileType, IStat, IWatchOptions, FileOpenOptions } from "vs/platform/files/common/files"; |
| 10 | +import { IRemoteAgentEnvironment } from "vs/platform/remote/common/remoteAgentEnvironment"; |
| 11 | + |
| 12 | +/** |
| 13 | + * See: src/vs/platform/remote/common/remoteAgentFileSystemChannel.ts. |
| 14 | + */ |
| 15 | +export class FileProviderChannel implements IServerChannel { |
| 16 | + public listen(_context: any, event: string): Event<any> { |
| 17 | + switch (event) { |
| 18 | + case "filechange": |
| 19 | + // TODO: not sure what to do here yet |
| 20 | + return new Emitter().event; |
| 21 | + } |
| 22 | + |
| 23 | + throw new Error(`Invalid listen "${event}"`); |
| 24 | + } |
| 25 | + |
| 26 | + public call(_: unknown, command: string, args?: any): Promise<any> { |
| 27 | + console.log("got call", command, args); |
| 28 | + switch (command) { |
| 29 | + case "stat": return this.stat(args[0]); |
| 30 | + case "open": return this.open(args[0], args[1]); |
| 31 | + case "close": return this.close(args[0]); |
| 32 | + case "read": return this.read(args[0], args[1], args[2], args[3], args[4]); |
| 33 | + case "write": return this.write(args[0], args[1], args[2], args[3], args[4]); |
| 34 | + case "delete": return this.delete(args[0], args[1]); |
| 35 | + case "mkdir": return this.mkdir(args[0]); |
| 36 | + case "readdir": return this.readdir(args[0]); |
| 37 | + case "rename": return this.rename(args[0], args[1], args[2]); |
| 38 | + case "copy": return this.copy(args[0], args[1], args[2]); |
| 39 | + case "watch": return this.watch(args[0], args[1]); |
| 40 | + case "unwatch": return this.unwatch(args[0]), args[1]; |
| 41 | + } |
| 42 | + |
| 43 | + throw new Error(`Invalid call "${command}"`); |
| 44 | + } |
| 45 | + |
| 46 | + private async stat(resource: URI): Promise<IStat> { |
| 47 | + throw new Error("not implemented"); |
| 48 | + } |
| 49 | + |
| 50 | + private async open(resource: URI, opts: FileOpenOptions): Promise<number> { |
| 51 | + throw new Error("not implemented"); |
| 52 | + } |
| 53 | + |
| 54 | + private async close(fd: number): Promise<void> { |
| 55 | + throw new Error("not implemented"); |
| 56 | + } |
| 57 | + |
| 58 | + private async read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { |
| 59 | + throw new Error("not implemented"); |
| 60 | + } |
| 61 | + |
| 62 | + private async write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number> { |
| 63 | + throw new Error("not implemented"); |
| 64 | + } |
| 65 | + |
| 66 | + private async delete(resource: URI, opts: FileDeleteOptions): Promise<void> { |
| 67 | + throw new Error("not implemented"); |
| 68 | + } |
| 69 | + |
| 70 | + private async mkdir(resource: URI): Promise<void> { |
| 71 | + throw new Error("not implemented"); |
| 72 | + } |
| 73 | + |
| 74 | + private async readdir(resource: URI): Promise<[string, FileType][]> { |
| 75 | + throw new Error("not implemented"); |
| 76 | + } |
| 77 | + |
| 78 | + private async rename(resource: URI, target: URI, opts: FileOverwriteOptions): Promise<void> { |
| 79 | + throw new Error("not implemented"); |
| 80 | + } |
| 81 | + |
| 82 | + private copy(resource: URI, target: URI, opts: FileOverwriteOptions): Promise<void> { |
| 83 | + throw new Error("not implemented"); |
| 84 | + } |
| 85 | + |
| 86 | + private watch(resource: URI, opts: IWatchOptions): Promise<void> { |
| 87 | + throw new Error("not implemented"); |
| 88 | + } |
| 89 | + |
| 90 | + private unwatch(resource: URI): void { |
| 91 | + throw new Error("not implemented"); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +/** |
| 96 | + * See: src/vs/workbench/services/remote/common/remoteAgentEnvironmentChannel.ts. |
| 97 | + */ |
| 98 | +export class ExtensionEnvironmentChannel implements IServerChannel { |
| 99 | + public constructor(private readonly environment: IEnvironmentService) {} |
| 100 | + |
| 101 | + public listen(_context: any, event: string): Event<any> { |
| 102 | + throw new Error(`Invalid listen "${event}"`); |
| 103 | + } |
| 104 | + |
| 105 | + public call(_: unknown, command: string, args?: any): Promise<any> { |
| 106 | + switch (command) { |
| 107 | + case "getEnvironmentData": return this.getEnvironmentData(); |
| 108 | + case "getDiagnosticInfo": return this.getDiagnosticInfo(); |
| 109 | + case "disableTelemetry": return this.disableTelemetry(); |
| 110 | + } |
| 111 | + throw new Error(`Invalid call "${command}"`); |
| 112 | + } |
| 113 | + |
| 114 | + private async getEnvironmentData(): Promise<IRemoteAgentEnvironment> { |
| 115 | + return { |
| 116 | + pid: process.pid, |
| 117 | + appRoot: URI.file(this.environment.appRoot), |
| 118 | + appSettingsHome: this.environment.appSettingsHome, |
| 119 | + settingsPath: this.environment.machineSettingsHome, |
| 120 | + logsPath: URI.file(this.environment.logsPath), |
| 121 | + extensionsPath: URI.file(this.environment.extensionsPath), |
| 122 | + extensionHostLogsPath: URI.file(path.join(this.environment.logsPath, "extension-host")), // TODO |
| 123 | + globalStorageHome: URI.file(this.environment.globalStorageHome), |
| 124 | + userHome: URI.file(this.environment.userHome), |
| 125 | + extensions: [], // TODO |
| 126 | + os: OS, |
| 127 | + }; |
| 128 | + } |
| 129 | + |
| 130 | + private getDiagnosticInfo(): Promise<IDiagnosticInfo> { |
| 131 | + throw new Error("not implemented"); |
| 132 | + } |
| 133 | + |
| 134 | + private disableTelemetry(): Promise<void> { |
| 135 | + throw new Error("not implemented"); |
| 136 | + } |
| 137 | +} |
0 commit comments