Skip to content

Commit 3ba93e8

Browse files
committed
Move more code to /common/
1 parent 2b0b602 commit 3ba93e8

7 files changed

Lines changed: 158 additions & 108 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { homedir } from 'os';
6868
import { join, sep } from 'vs/base/common/path';
6969
import { localize } from 'vs/nls';
7070
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
71-
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME } from 'vs/platform/remote/node/remoteAgentFileSystemChannel';
71+
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME } from 'vs/platform/remote/common/remoteAgentFileSystemChannel';
7272
import { ResolvedAuthority } from 'vs/platform/remote/common/remoteAuthorityResolver';
7373
import { SnapUpdateService } from 'vs/platform/update/electron-main/updateService.snap';
7474
import { IStorageMainService, StorageMainService } from 'vs/platform/storage/node/storageMainService';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { ResolvedAuthority, IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
7+
8+
export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService {
9+
10+
_serviceBrand: any;
11+
12+
constructor() {
13+
}
14+
15+
resolveAuthority(authority: string): Promise<ResolvedAuthority> {
16+
if (authority.indexOf(':') >= 0) {
17+
const pieces = authority.split(':');
18+
return Promise.resolve({ authority, host: pieces[0], port: parseInt(pieces[1], 10) });
19+
}
20+
return Promise.resolve({ authority, host: authority, port: 80 });
21+
}
22+
23+
setResolvedAuthority(resolvedAuthority: ResolvedAuthority) {
24+
throw new Error(`Not implemented`);
25+
}
26+
27+
setResolvedAuthorityError(authority: string, err: any): void {
28+
throw new Error(`Not implemented`);
29+
}
30+
}

src/vs/platform/remote/node/remoteAgentFileSystemChannel.ts renamed to src/vs/platform/remote/common/remoteAgentFileSystemChannel.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
99
import { generateUuid } from 'vs/base/common/uuid';
1010
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
1111
import { FileChangeType, FileDeleteOptions, FileOverwriteOptions, FileSystemProviderCapabilities, FileType, FileWriteOptions, IFileChange, IFileSystemProvider, IStat, IWatchOptions } from 'vs/platform/files/common/files';
12+
import { VSBuffer } from 'vs/base/common/buffer';
1213

1314
export const REMOTE_FILE_SYSTEM_CHANNEL_NAME = 'remotefilesystem';
1415

@@ -71,20 +72,17 @@ export class RemoteExtensionsFileSystemProvider extends Disposable implements IF
7172

7273
// --- forwarding calls
7374

74-
private static _asBuffer(data: Uint8Array): Buffer {
75-
return Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
76-
}
77-
7875
stat(resource: URI): Promise<IStat> {
7976
return this._channel.call('stat', [resource]);
8077
}
8178

82-
readFile(resource: URI): Promise<Uint8Array> {
83-
return this._channel.call('readFile', [resource]);
79+
async readFile(resource: URI): Promise<Uint8Array> {
80+
const buff = <VSBuffer>await this._channel.call('readFile', [resource]);
81+
return buff.buffer;
8482
}
8583

8684
writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> {
87-
const contents = RemoteExtensionsFileSystemProvider._asBuffer(content);
85+
const contents = VSBuffer.wrap(content);
8886
return this._channel.call('writeFile', [resource, contents, opts]);
8987
}
9088

src/vs/workbench/electron-browser/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { FileService2 } from 'vs/workbench/services/files2/common/fileService2';
4747
import { IFileService } from 'vs/platform/files/common/files';
4848
import { DiskFileSystemProvider } from 'vs/workbench/services/files2/electron-browser/diskFileSystemProvider';
4949
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
50-
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME, RemoteExtensionsFileSystemProvider } from 'vs/platform/remote/node/remoteAgentFileSystemChannel';
50+
import { REMOTE_FILE_SYSTEM_CHANNEL_NAME, RemoteExtensionsFileSystemProvider } from 'vs/platform/remote/common/remoteAgentFileSystemChannel';
5151

5252
class CodeRendererMain extends Disposable {
5353

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as nls from 'vs/nls';
7+
import { Disposable } from 'vs/base/common/lifecycle';
8+
import { IChannel, IServerChannel, getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
9+
import { Client } from 'vs/base/parts/ipc/common/ipc.net';
10+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
11+
import { connectRemoteAgentManagement, IConnectionOptions, IWebSocketFactory } from 'vs/platform/remote/common/remoteAgentConnection';
12+
import { IRemoteAgentConnection, IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
13+
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
14+
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
15+
import { RemoteAgentConnectionContext, IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
16+
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions';
17+
import { Registry } from 'vs/platform/registry/common/platform';
18+
import { RemoteExtensionEnvironmentChannelClient } from 'vs/workbench/services/remote/common/remoteAgentEnvironmentChannel';
19+
import { INotificationService } from 'vs/platform/notification/common/notification';
20+
21+
export abstract class AbstractRemoteAgentService extends Disposable implements IRemoteAgentService {
22+
23+
_serviceBrand: any;
24+
25+
private _environment: Promise<IRemoteAgentEnvironment | null> | null;
26+
27+
constructor(
28+
@IEnvironmentService protected readonly _environmentService: IEnvironmentService
29+
) {
30+
super();
31+
}
32+
33+
abstract getConnection(): IRemoteAgentConnection | null;
34+
35+
getEnvironment(bail?: boolean): Promise<IRemoteAgentEnvironment | null> {
36+
if (!this._environment) {
37+
const connection = this.getConnection();
38+
if (connection) {
39+
const client = new RemoteExtensionEnvironmentChannelClient(connection.getChannel('remoteextensionsenvironment'));
40+
this._environment = client.getEnvironmentData(connection.remoteAuthority, this._environmentService.extensionDevelopmentLocationURI);
41+
} else {
42+
this._environment = Promise.resolve(null);
43+
}
44+
}
45+
return bail ? this._environment : this._environment.then(undefined, () => null);
46+
}
47+
}
48+
49+
export class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection {
50+
51+
readonly remoteAuthority: string;
52+
private _connection: Promise<Client<RemoteAgentConnectionContext>> | null;
53+
54+
constructor(
55+
remoteAuthority: string,
56+
private _commit: string | undefined,
57+
private _webSocketFactory: IWebSocketFactory,
58+
private _environmentService: IEnvironmentService,
59+
private _remoteAuthorityResolverService: IRemoteAuthorityResolverService
60+
) {
61+
super();
62+
this.remoteAuthority = remoteAuthority;
63+
this._connection = null;
64+
}
65+
66+
getChannel<T extends IChannel>(channelName: string): T {
67+
return <T>getDelayedChannel(this._getOrCreateConnection().then(c => c.getChannel(channelName)));
68+
}
69+
70+
registerChannel<T extends IServerChannel<RemoteAgentConnectionContext>>(channelName: string, channel: T): void {
71+
this._getOrCreateConnection().then(client => client.registerChannel(channelName, channel));
72+
}
73+
74+
private _getOrCreateConnection(): Promise<Client<RemoteAgentConnectionContext>> {
75+
if (!this._connection) {
76+
this._connection = this._createConnection();
77+
}
78+
return this._connection;
79+
}
80+
81+
private async _createConnection(): Promise<Client<RemoteAgentConnectionContext>> {
82+
const options: IConnectionOptions = {
83+
isBuilt: this._environmentService.isBuilt,
84+
commit: this._commit,
85+
webSocketFactory: this._webSocketFactory,
86+
addressProvider: {
87+
getAddress: async () => {
88+
const { host, port } = await this._remoteAuthorityResolverService.resolveAuthority(this.remoteAuthority);
89+
return { host, port };
90+
}
91+
}
92+
};
93+
const connection = await connectRemoteAgentManagement(options, this.remoteAuthority, `renderer`);
94+
this._register(connection);
95+
return connection.client;
96+
}
97+
}
98+
99+
class RemoteConnectionFailureNotificationContribution implements IWorkbenchContribution {
100+
101+
constructor(
102+
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
103+
@INotificationService notificationService: INotificationService,
104+
) {
105+
// Let's cover the case where connecting to fetch the remote extension info fails
106+
remoteAgentService.getEnvironment(true)
107+
.then(undefined, err => notificationService.error(nls.localize('connectionError', "Failed to connect to the remote extension host agent (Error: {0})", err ? err.message : '')));
108+
}
109+
110+
}
111+
112+
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench);
113+
workbenchRegistry.registerWorkbenchContribution(RemoteConnectionFailureNotificationContribution, LifecyclePhase.Ready);

src/vs/workbench/services/remote/common/remoteAgentService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IRemoteAgentService {
1515
_serviceBrand: any;
1616

1717
getConnection(): IRemoteAgentConnection | null;
18-
getEnvironment(): Promise<IRemoteAgentEnvironment | null>;
18+
getEnvironment(bail?: boolean): Promise<IRemoteAgentEnvironment | null>;
1919
}
2020

2121
export interface IRemoteAgentConnection {

src/vs/workbench/services/remote/electron-browser/remoteAgentServiceImpl.ts

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

6-
import { Disposable } from 'vs/base/common/lifecycle';
7-
import { IChannel, IServerChannel, getDelayedChannel } from 'vs/base/parts/ipc/common/ipc';
8-
import { Client } from 'vs/base/parts/ipc/common/ipc.net';
96
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
10-
import { connectRemoteAgentManagement, IConnectionOptions } from 'vs/platform/remote/common/remoteAgentConnection';
117
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
12-
import { IRemoteAgentConnection, IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
8+
import { IRemoteAgentConnection } from 'vs/workbench/services/remote/common/remoteAgentService';
139
import { IRemoteAuthorityResolverService } from 'vs/platform/remote/common/remoteAuthorityResolver';
14-
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
15-
import { RemoteAgentConnectionContext, IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment';
16-
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions } from 'vs/workbench/common/contributions';
17-
import { Registry } from 'vs/platform/registry/common/platform';
18-
import { RemoteExtensionEnvironmentChannelClient } from 'vs/workbench/services/remote/common/remoteAgentEnvironmentChannel';
19-
import { INotificationService } from 'vs/platform/notification/common/notification';
20-
import { localize } from 'vs/nls';
2110
import product from 'vs/platform/product/node/product';
2211
import { nodeWebSocketFactory } from 'vs/platform/remote/node/nodeWebSocketFactory';
12+
import { AbstractRemoteAgentService, RemoteAgentConnection } from 'vs/workbench/services/remote/common/abstractRemoteAgentService';
2313

24-
export class RemoteAgentService extends Disposable implements IRemoteAgentService {
25-
26-
_serviceBrand: any;
14+
export class RemoteAgentService extends AbstractRemoteAgentService {
2715

2816
private readonly _connection: IRemoteAgentConnection | null = null;
29-
private _environment: Promise<IRemoteAgentEnvironment | null> | null;
3017

31-
constructor(
32-
{ remoteAuthority }: IWindowConfiguration,
33-
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
18+
constructor({ remoteAuthority }: IWindowConfiguration,
19+
@IEnvironmentService environmentService: IEnvironmentService,
3420
@IRemoteAuthorityResolverService remoteAuthorityResolverService: IRemoteAuthorityResolverService
3521
) {
36-
super();
22+
super(environmentService);
3723
if (remoteAuthority) {
38-
this._connection = this._register(new RemoteAgentConnection(remoteAuthority, _environmentService, remoteAuthorityResolverService));
24+
this._connection = this._register(new RemoteAgentConnection(remoteAuthority, product.commit, nodeWebSocketFactory, environmentService, remoteAuthorityResolverService));
3925
}
4026
}
4127

4228
getConnection(): IRemoteAgentConnection | null {
4329
return this._connection;
4430
}
45-
46-
getEnvironment(bail?: boolean): Promise<IRemoteAgentEnvironment | null> {
47-
if (!this._environment) {
48-
const connection = this.getConnection();
49-
if (connection) {
50-
const client = new RemoteExtensionEnvironmentChannelClient(connection.getChannel('remoteextensionsenvironment'));
51-
this._environment = client.getEnvironmentData(connection.remoteAuthority, this._environmentService.extensionDevelopmentLocationURI);
52-
} else {
53-
this._environment = Promise.resolve(null);
54-
}
55-
}
56-
return bail ? this._environment : this._environment.then(undefined, () => null);
57-
}
5831
}
59-
60-
class RemoteAgentConnection extends Disposable implements IRemoteAgentConnection {
61-
62-
readonly remoteAuthority: string;
63-
private _connection: Promise<Client<RemoteAgentConnectionContext>> | null;
64-
65-
constructor(
66-
remoteAuthority: string,
67-
private _environmentService: IEnvironmentService,
68-
private _remoteAuthorityResolverService: IRemoteAuthorityResolverService
69-
) {
70-
super();
71-
this.remoteAuthority = remoteAuthority;
72-
this._connection = null;
73-
}
74-
75-
getChannel<T extends IChannel>(channelName: string): T {
76-
return <T>getDelayedChannel(this._getOrCreateConnection().then(c => c.getChannel(channelName)));
77-
}
78-
79-
registerChannel<T extends IServerChannel<RemoteAgentConnectionContext>>(channelName: string, channel: T): void {
80-
this._getOrCreateConnection().then(client => client.registerChannel(channelName, channel));
81-
}
82-
83-
private _getOrCreateConnection(): Promise<Client<RemoteAgentConnectionContext>> {
84-
if (!this._connection) {
85-
this._connection = this._createConnection();
86-
}
87-
return this._connection;
88-
}
89-
90-
private async _createConnection(): Promise<Client<RemoteAgentConnectionContext>> {
91-
const options: IConnectionOptions = {
92-
isBuilt: this._environmentService.isBuilt,
93-
commit: product.commit,
94-
webSocketFactory: nodeWebSocketFactory,
95-
addressProvider: {
96-
getAddress: async () => {
97-
const { host, port } = await this._remoteAuthorityResolverService.resolveAuthority(this.remoteAuthority);
98-
return { host, port };
99-
}
100-
}
101-
};
102-
const connection = await connectRemoteAgentManagement(options, this.remoteAuthority, `renderer`);
103-
this._register(connection);
104-
return connection.client;
105-
}
106-
}
107-
108-
class RemoteConnectionFailureNotificationContribution implements IWorkbenchContribution {
109-
110-
constructor(
111-
@IRemoteAgentService remoteAgentService: RemoteAgentService,
112-
@INotificationService notificationService: INotificationService,
113-
) {
114-
// Let's cover the case where connecting to fetch the remote extension info fails
115-
remoteAgentService.getEnvironment(true)
116-
.then(undefined, err => notificationService.error(localize('connectionError', "Failed to connect to the remote extension host agent (Error: {0})", err ? err.message : '')));
117-
}
118-
119-
}
120-
121-
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench);
122-
workbenchRegistry.registerWorkbenchContribution(RemoteConnectionFailureNotificationContribution, LifecyclePhase.Ready);

0 commit comments

Comments
 (0)