Skip to content

Commit

Permalink
Add tunnel list changed event API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Jan 20, 2020
1 parent 7cfac76 commit 017aef6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ declare module 'vscode' {
* Note that these are of type TunnelDescription and cannot be disposed.
*/
export let tunnels: Thenable<TunnelDescription[]>;

/**
* Fired when the list of tunnels has changed.
*/
export const onDidTunnelsChange: Event<void>;
}

export interface ResourceLabelFormatter {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/api/browser/mainThreadTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun
) {
super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTunnelService);
this._register(tunnelService.onTunnelOpened(() => this._proxy.$onDidTunnelsChange()));
this._register(tunnelService.onTunnelClosed(() => this._proxy.$onDidTunnelsChange()));
}

async $openTunnel(tunnelOptions: TunnelOptions): Promise<TunnelDto | undefined> {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
get tunnels() {
return extHostTunnelService.getTunnels();
},
onDidTunnelsChange: (listener, thisArg?, disposables?) => {
return extHostTunnelService.onDidTunnelsChange(listener, thisArg, disposables);
}
};

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 @@ -1423,6 +1423,7 @@ export interface ExtHostTunnelServiceShape {
$filterCandidates(candidates: { host: string, port: number, detail: string }[]): Promise<boolean[]>;
$forwardPort(tunnelOptions: TunnelOptions): Promise<TunnelDto> | undefined;
$closeTunnel(remote: { host: string, port: number }): Promise<void>;
$onDidTunnelsChange(): Promise<void>;
}

// --- proxy identifiers
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/api/common/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import type * as vscode from 'vscode';
import { RemoteTunnel, TunnelOptions } from 'vs/platform/remote/common/tunnel';
import { IDisposable } from 'vs/base/common/lifecycle';
import { Emitter } from 'vs/base/common/event';

export interface TunnelDto {
remoteAddress: { port: number, host: string };
Expand All @@ -32,13 +33,16 @@ export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
readonly _serviceBrand: undefined;
openTunnel(forward: TunnelOptions): Promise<vscode.Tunnel | undefined>;
getTunnels(): Promise<vscode.TunnelDescription[]>;
onDidTunnelsChange: vscode.Event<void>;
setTunnelExtensionFunctions(provider: vscode.RemoteAuthorityResolver | undefined): Promise<IDisposable>;
}

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

export class ExtHostTunnelService implements IExtHostTunnelService {
_serviceBrand: undefined;
onDidTunnelsChange: vscode.Event<void> = (new Emitter<void>()).event;

async openTunnel(forward: TunnelOptions): Promise<vscode.Tunnel | undefined> {
return undefined;
}
Expand All @@ -54,5 +58,5 @@ export class ExtHostTunnelService implements IExtHostTunnelService {
async setTunnelExtensionFunctions(provider: vscode.RemoteAuthorityResolver | undefined): Promise<IDisposable> { return { dispose: () => { } }; }
$forwardPort(tunnelOptions: TunnelOptions): Promise<TunnelDto> | undefined { return undefined; }
async $closeTunnel(remote: { host: string, port: number }): Promise<void> { }

async $onDidTunnelsChange(): Promise<void> { }
}
6 changes: 6 additions & 0 deletions src/vs/workbench/api/node/extHostTunnelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
private _forwardPortProvider: ((tunnelOptions: TunnelOptions) => Thenable<vscode.Tunnel> | undefined) | undefined;
private _showCandidatePort: (host: string, port: number, detail: string) => Thenable<boolean> = () => { return Promise.resolve(true); };
private _extensionTunnels: Map<string, Map<number, vscode.Tunnel>> = new Map();
private _onDidTunnelsChange: Emitter<void> = new Emitter<void>();
onDidTunnelsChange: vscode.Event<void> = this._onDidTunnelsChange.event;

constructor(
@IExtHostRpcService extHostRpc: IExtHostRpcService,
Expand Down Expand Up @@ -104,6 +106,10 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
}
}

async $onDidTunnelsChange(): Promise<void> {
this._onDidTunnelsChange.fire();
}

$forwardPort(tunnelOptions: TunnelOptions): Promise<TunnelDto> | undefined {
if (this._forwardPortProvider) {
const providedPort = this._forwardPortProvider!(tunnelOptions);
Expand Down

0 comments on commit 017aef6

Please sign in to comment.