Skip to content

Commit

Permalink
First pass at port API needed for port UI (#85117)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Dec 10, 2019
1 parent 1f0a0a7 commit 9566da2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
42 changes: 40 additions & 2 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

declare module 'vscode' {

//#region Alex - resolvers
//#region Alex - resolvers, AlexR - ports

export interface RemoteAuthorityResolverContext {
resolveAttempt: number;
Expand All @@ -33,7 +33,31 @@ declare module 'vscode' {
extensionHostEnv?: { [key: string]: string | null };
}

export type ResolverResult = ResolvedAuthority & ResolvedOptions;
export interface TunnelOptions {
remote: { port: number, host: string };
localPort?: number;
name?: string;
closeable?: boolean;
}

export interface Tunnel extends Disposable {
remote: { port: number, host: string };
local: { port: number, host: string };
}

/**
* Used as part of the ResolverResult if the extension has any candidate, published, or forwarded ports.
*/
export interface TunnelInformation {
/**
* Tunnels that are detected by the extension. The remotePort is used for display purposes.
* The localAddress should be the complete local address(ex. localhost:1234) for connecting to the port. Tunnels provided through
* detected are read-only from the forwarded ports UI.
*/
detectedTunnels?: { remotePort: number, localAddress: string }[];
}

export type ResolverResult = ResolvedAuthority & ResolvedOptions & TunnelInformation;

export class RemoteAuthorityResolverError extends Error {
static NotAvailable(message?: string, handled?: boolean): RemoteAuthorityResolverError;
Expand All @@ -44,6 +68,20 @@ declare module 'vscode' {

export interface RemoteAuthorityResolver {
resolve(authority: string, context: RemoteAuthorityResolverContext): ResolverResult | Thenable<ResolverResult>;
/**
* Can be optionally implemented if the extension can forward ports better than the core.
* When not implemented, the core will use its default forwarding logic.
* When implemented, the core will use this to forward ports.
*/
forwardPort?(tunnelOptions: TunnelOptions): Thenable<Tunnel | undefined>;
}

export namespace workspace {
/**
* Forwards a port.
* @param forward The `localPort` is a suggestion only. If that port is not available another will be chosen.
*/
export function makeTunnel(forward: TunnelOptions): Thenable<Tunnel>;
}

export interface ResourceLabelFormatter {
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IURITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
import { IExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelService';

export interface IExtensionApiFactory {
(extension: IExtensionDescription, registry: ExtensionDescriptionRegistry, configProvider: ExtHostConfigProvider): typeof vscode;
Expand All @@ -86,13 +87,15 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const rpcProtocol = accessor.get(IExtHostRpcService);
const extHostStorage = accessor.get(IExtHostStorage);
const extHostLogService = accessor.get(ILogService);
const extHostTunnelService = accessor.get(IExtHostTunnelService);

// register addressable instances
rpcProtocol.set(ExtHostContext.ExtHostLogService, <ExtHostLogServiceShape><any>extHostLogService);
rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
rpcProtocol.set(ExtHostContext.ExtHostStorage, extHostStorage);
rpcProtocol.set(ExtHostContext.ExtHostTunnelService, extHostTunnelService);

// automatically create and register addressable instances
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, accessor.get(IExtHostDecorations));
Expand Down Expand Up @@ -710,6 +713,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
onWillRenameFiles: (listener: (e: vscode.FileWillRenameEvent) => any, thisArg?: any, disposables?: vscode.Disposable[]) => {
return extHostFileSystemEvent.getOnWillRenameFileEvent(extension)(listener, thisArg, disposables);
},
makeTunnel: (forward: vscode.TunnelOptions) => {
checkProposedApiEnabled(extension);
return extHostTunnelService.makeTunnel(forward);
}
};

Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,11 @@ export interface ExtHostStorageShape {
$acceptValue(shared: boolean, key: string, value: object | undefined): void;
}


export interface ExtHostTunnelServiceShape {

}

// --- proxy identifiers

export const MainContext = {
Expand Down Expand Up @@ -1464,5 +1469,6 @@ export const ExtHostContext = {
ExtHostStorage: createMainId<ExtHostStorageShape>('ExtHostStorage'),
ExtHostUrls: createExtId<ExtHostUrlsShape>('ExtHostUrls'),
ExtHostOutputService: createMainId<ExtHostOutputServiceShape>('ExtHostOutputService'),
ExtHosLabelService: createMainId<ExtHostLabelServiceShape>('ExtHostLabelService')
ExtHosLabelService: createMainId<ExtHostLabelServiceShape>('ExtHostLabelService'),
ExtHostTunnelService: createMainId<ExtHostTunnelServiceShape>('ExtHostTunnelService')
};
21 changes: 21 additions & 0 deletions src/vs/workbench/api/common/extHostTunnelService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ExtHostTunnelServiceShape } from 'vs/workbench/api/common/extHost.protocol';
import * as vscode from 'vscode';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
makeTunnel(forward: vscode.TunnelOptions): Promise<vscode.Tunnel>;
}

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

export class ExtHostTunnelService implements IExtHostTunnelService {
makeTunnel(forward: vscode.TunnelOptions): Promise<vscode.Tunnel> {
throw new Error('Method not implemented.');
}
}

2 changes: 2 additions & 0 deletions src/vs/workbench/api/node/extHost.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionS
import { IExtHostStorage, ExtHostStorage } from 'vs/workbench/api/common/extHostStorage';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
import { IExtHostTunnelService, ExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelService';

// register singleton services
registerSingleton(ILogService, ExtHostLogService);
Expand All @@ -42,3 +43,4 @@ registerSingleton(IExtHostSearch, NativeExtHostSearch);
registerSingleton(IExtensionStoragePaths, ExtensionStoragePaths);
registerSingleton(IExtHostExtensionService, ExtHostExtensionService);
registerSingleton(IExtHostStorage, ExtHostStorage);
registerSingleton(IExtHostTunnelService, ExtHostTunnelService);
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ExtHostExtensionService } from 'vs/workbench/api/worker/extHostExtensio
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostLogService } from 'vs/workbench/api/worker/extHostLogService';
import { IExtHostTunnelService, ExtHostTunnelService } from 'vs/workbench/api/common/extHostTunnelService';

// register singleton services
registerSingleton(ILogService, ExtHostLogService);
Expand All @@ -33,6 +34,7 @@ registerSingleton(IExtHostDocumentsAndEditors, ExtHostDocumentsAndEditors);
registerSingleton(IExtHostStorage, ExtHostStorage);
registerSingleton(IExtHostExtensionService, ExtHostExtensionService);
registerSingleton(IExtHostSearch, ExtHostSearch);
registerSingleton(IExtHostTunnelService, ExtHostTunnelService);

// register services that only throw errors
function NotImplementedProxy<T>(name: ServiceIdentifier<T>): { new(): T } {
Expand Down

0 comments on commit 9566da2

Please sign in to comment.