Skip to content

Commit

Permalink
Implement tunnelInformation
Browse files Browse the repository at this point in the history
Part of #81388
  • Loading branch information
alexr00 committed Dec 11, 2019
1 parent bb6dc66 commit e7dd2dd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 22 deletions.
8 changes: 6 additions & 2 deletions src/vs/workbench/api/browser/mainThreadTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ export class MainThreadTunnelService implements MainThreadTunnelServiceShape {
}

async $openTunnel(tunnelOptions: TunnelOptions): Promise<TunnelDto | undefined> {
const tunnel = await this.remoteExplorerService.tunnelModel.forward(tunnelOptions.remote.port, tunnelOptions.localPort, tunnelOptions.name);
const tunnel = await this.remoteExplorerService.forward(tunnelOptions.remote.port, tunnelOptions.localPort, tunnelOptions.name);
if (tunnel) {
return { remote: { host: tunnel.tunnelRemoteHost, port: tunnel.tunnelRemotePort }, localAddress: tunnel.localAddress };
}
return undefined;
}

async $closeTunnel(remotePort: number): Promise<void> {
return this.remoteExplorerService.tunnelModel.close(remotePort);
return this.remoteExplorerService.close(remotePort);
}

$addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[]): Promise<void> {
return Promise.resolve(this.remoteExplorerService.addDetected(tunnels));
}

dispose(): void {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ export interface MainThreadWindowShape extends IDisposable {
export interface MainThreadTunnelServiceShape extends IDisposable {
$openTunnel(tunnelOptions: TunnelOptions): Promise<TunnelDto | undefined>;
$closeTunnel(remotePort: number): Promise<void>;
$addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[]): Promise<void>;
}

// -- extension host
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/api/common/extHostExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitData
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { IExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelService';

interface ITestRunner {
/** Old test runner API, as exported from `vscode/lib/testrunner` */
Expand Down Expand Up @@ -76,6 +77,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
protected readonly _extHostWorkspace: ExtHostWorkspace;
protected readonly _extHostConfiguration: ExtHostConfiguration;
protected readonly _logService: ILogService;
protected readonly _extHostTunnelService: IExtHostTunnelService;

protected readonly _mainThreadWorkspaceProxy: MainThreadWorkspaceShape;
protected readonly _mainThreadTelemetryProxy: MainThreadTelemetryShape;
Expand Down Expand Up @@ -104,7 +106,8 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
@IExtHostConfiguration extHostConfiguration: IExtHostConfiguration,
@ILogService logService: ILogService,
@IExtHostInitDataService initData: IExtHostInitDataService,
@IExtensionStoragePaths storagePath: IExtensionStoragePaths
@IExtensionStoragePaths storagePath: IExtensionStoragePaths,
@IExtHostTunnelService extHostTunnelService: IExtHostTunnelService
) {
this._hostUtils = hostUtils;
this._extHostContext = extHostContext;
Expand All @@ -113,6 +116,7 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
this._extHostWorkspace = extHostWorkspace;
this._extHostConfiguration = extHostConfiguration;
this._logService = logService;
this._extHostTunnelService = extHostTunnelService;
this._disposables = new DisposableStore();

this._mainThreadWorkspaceProxy = this._extHostContext.getProxy(MainContext.MainThreadWorkspace);
Expand Down Expand Up @@ -652,6 +656,8 @@ export abstract class AbstractExtHostExtensionService implements ExtHostExtensio
extensionHostEnv: result.extensionHostEnv
};

await this._extHostTunnelService.addDetected(result.detectedTunnels);

return {
type: 'ok',
value: {
Expand Down
10 changes: 10 additions & 0 deletions src/vs/workbench/api/common/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ export interface TunnelDto {
}

export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
readonly _serviceBrand: undefined;
makeTunnel(forward: TunnelOptions): Promise<vscode.Tunnel | undefined>;
addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[] | undefined): Promise<void>;
}

export const IExtHostTunnelService = createDecorator<IExtHostTunnelService>('IExtHostTunnelService');


export class ExtHostTunnelService extends Disposable implements IExtHostTunnelService {
readonly _serviceBrand: undefined;
private readonly _proxy: MainThreadTunnelServiceShape;

constructor(
Expand All @@ -52,5 +55,12 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
}
return undefined;
}

async addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[] | undefined): Promise<void> {
if (tunnels) {
return this._proxy.$addDetected(tunnels);
}
}

}

32 changes: 16 additions & 16 deletions src/vs/workbench/contrib/remote/browser/tunnelView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TunnelTreeVirtualDelegate implements IListVirtualDelegate<ITunnelItem> {
export interface ITunnelViewModel {
onForwardedPortsChanged: Event<void>;
readonly forwarded: TunnelItem[];
readonly published: TunnelItem[];
readonly detected: TunnelItem[];
readonly candidates: TunnelItem[];
readonly groups: ITunnelGroup[];
}
Expand Down Expand Up @@ -79,11 +79,11 @@ export class TunnelViewModel extends Disposable implements ITunnelViewModel {
items: this.forwarded
});
}
if (this.model.published.size > 0) {
if (this.model.detected.size > 0) {
groups.push({
label: nls.localize('remote.tunnelsView.published', "Published"),
tunnelType: TunnelType.Published,
items: this.published
label: nls.localize('remote.tunnelsView.detected', "Detected"),
tunnelType: TunnelType.Detected,
items: this.detected
});
}
const candidates = this.candidates;
Expand All @@ -107,9 +107,9 @@ export class TunnelViewModel extends Disposable implements ITunnelViewModel {
});
}

get published(): TunnelItem[] {
return Array.from(this.model.published.values()).map(tunnel => {
return new TunnelItem(TunnelType.Published, tunnel.remote, tunnel.localAddress, false, tunnel.name, tunnel.description);
get detected(): TunnelItem[] {
return Array.from(this.model.detected.values()).map(tunnel => {
return new TunnelItem(TunnelType.Detected, tunnel.remote, tunnel.localAddress, false, tunnel.name, tunnel.description);
});
}

Expand All @@ -118,7 +118,7 @@ export class TunnelViewModel extends Disposable implements ITunnelViewModel {
const values = this.model.candidates.values();
let iterator = values.next();
while (!iterator.done) {
if (!this.model.forwarded.has(iterator.value.remote) && !this.model.published.has(iterator.value.remote)) {
if (!this.model.forwarded.has(iterator.value.remote) && !this.model.detected.has(iterator.value.remote)) {
candidates.push(new TunnelItem(TunnelType.Candidate, iterator.value.remote, iterator.value.localAddress, false, undefined, iterator.value.description));
}
iterator = values.next();
Expand Down Expand Up @@ -324,7 +324,7 @@ class TunnelDataSource implements IAsyncDataSource<ITunnelViewModel, ITunnelItem

enum TunnelType {
Candidate = 'Candidate',
Published = 'Published',
Detected = 'Detected',
Forwarded = 'Forwarded',
Add = 'Add'
}
Expand Down Expand Up @@ -645,7 +645,7 @@ namespace OpenPortInBrowserAction {
if (arg instanceof TunnelItem) {
const model = accessor.get(IRemoteExplorerService).tunnelModel;
const openerService = accessor.get(IOpenerService);
const tunnel = model.forwarded.has(arg.remote) ? model.forwarded.get(arg.remote) : model.published.get(arg.remote);
const tunnel = model.forwarded.has(arg.remote) ? model.forwarded.get(arg.remote) : model.detected.get(arg.remote);
let address: string | undefined;
if (tunnel && tunnel.localAddress && (address = model.address(tunnel.remote))) {
return openerService.open(URI.parse('http://' + address));
Expand Down Expand Up @@ -696,7 +696,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
id: CopyAddressAction.ID,
title: CopyAddressAction.LABEL,
},
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Published))
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Detected))
}));
MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
group: '0_manage',
Expand All @@ -705,7 +705,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
id: OpenPortInBrowserAction.ID,
title: OpenPortInBrowserAction.LABEL,
},
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Published))
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Detected))
}));
MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
group: '0_manage',
Expand All @@ -723,7 +723,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
id: ForwardPortAction.ID,
title: ForwardPortAction.LABEL,
},
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Candidate), TunnelTypeContextKey.isEqualTo(TunnelType.Published))
when: TunnelTypeContextKey.isEqualTo(TunnelType.Candidate)
}));
MenuRegistry.appendMenuItem(MenuId.TunnelContext, ({
group: '0_manage',
Expand All @@ -742,7 +742,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelInline, ({
title: OpenPortInBrowserAction.LABEL,
icon: { id: 'codicon/globe' }
},
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Published))
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Forwarded), TunnelTypeContextKey.isEqualTo(TunnelType.Detected))
}));
MenuRegistry.appendMenuItem(MenuId.TunnelInline, ({
order: 0,
Expand All @@ -751,7 +751,7 @@ MenuRegistry.appendMenuItem(MenuId.TunnelInline, ({
title: ForwardPortAction.LABEL,
icon: { id: 'codicon/plus' }
},
when: ContextKeyExpr.or(TunnelTypeContextKey.isEqualTo(TunnelType.Candidate), TunnelTypeContextKey.isEqualTo(TunnelType.Published))
when: TunnelTypeContextKey.isEqualTo(TunnelType.Candidate)
}));
MenuRegistry.appendMenuItem(MenuId.TunnelInline, ({
order: 2,
Expand Down
36 changes: 33 additions & 3 deletions src/vs/workbench/services/remote/common/remoteExplorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Tunnel {

export class TunnelModel extends Disposable {
readonly forwarded: Map<number, Tunnel>;
readonly published: Map<number, Tunnel>;
readonly detected: Map<number, Tunnel>;
readonly candidates: Map<number, Tunnel>;
private _onForwardPort: Emitter<Tunnel> = new Emitter();
public onForwardPort: Event<Tunnel> = this._onForwardPort.event;
Expand All @@ -53,7 +53,7 @@ export class TunnelModel extends Disposable {
});
});

this.published = new Map();
this.detected = new Map();
this.candidates = new Map();
this._register(this.tunnelService.onTunnelOpened(tunnel => {
if (this.candidates.has(tunnel.tunnelRemotePort)) {
Expand Down Expand Up @@ -99,6 +99,9 @@ export class TunnelModel extends Disposable {
if (this.forwarded.has(remote)) {
this.forwarded.get(remote)!.name = name;
this._onPortName.fire(remote);
} else if (this.detected.has(remote)) {
this.detected.get(remote)!.name = name;
this._onPortName.fire(remote);
}
}

Expand All @@ -107,7 +110,17 @@ export class TunnelModel extends Disposable {
}

address(remote: number): string | undefined {
return (this.forwarded.get(remote) || this.published.get(remote))?.localAddress;
return (this.forwarded.get(remote) || this.detected.get(remote))?.localAddress;
}

addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[]): void {
tunnels.forEach(tunnel => {
this.detected.set(tunnel.remote.port, {
remote: tunnel.remote.port,
localAddress: tunnel.localAddress,
closeable: false
});
});
}
}

Expand All @@ -120,6 +133,9 @@ export interface IRemoteExplorerService {
onDidChangeEditable: Event<number | undefined>;
setEditable(remote: number | undefined, data: IEditableData | null): void;
getEditableData(remote: number | undefined): IEditableData | undefined;
forward(remote: number, local?: number, name?: string): Promise<RemoteTunnel | void>;
close(remote: number): Promise<void>;
addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[] | undefined): void;
}

export interface HelpInformation {
Expand Down Expand Up @@ -221,6 +237,20 @@ class RemoteExplorerService implements IRemoteExplorerService {
return this._tunnelModel;
}

forward(remote: number, local?: number, name?: string): Promise<RemoteTunnel | void> {
return this.tunnelModel.forward(remote, local, name);
}

close(remote: number): Promise<void> {
return this.tunnelModel.close(remote);
}

addDetected(tunnels: { remote: { port: number, host: string }, localAddress: string }[] | undefined): void {
if (tunnels) {
this.tunnelModel.addDetected(tunnels);
}
}

setEditable(remote: number | undefined, data: IEditableData | null): void {
if (!data) {
this.editable = undefined;
Expand Down

0 comments on commit e7dd2dd

Please sign in to comment.