diff --git a/src/vs/workbench/api/browser/mainThreadTunnelService.ts b/src/vs/workbench/api/browser/mainThreadTunnelService.ts index 846d68c2d14..ab5fabffdc2 100644 --- a/src/vs/workbench/api/browser/mainThreadTunnelService.ts +++ b/src/vs/workbench/api/browser/mainThreadTunnelService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as nls from 'vs/nls'; -import { MainThreadTunnelServiceShape, MainContext, ExtHostContext, ExtHostTunnelServiceShape, CandidatePortSource, PortAttributesProviderSelector, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; +import { MainThreadTunnelServiceShape, MainContext, ExtHostContext, ExtHostTunnelServiceShape, CandidatePortSource, PortAttributesSelector, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; import { TunnelDtoConverter } from 'vs/workbench/api/common/extHostTunnelService'; import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'; import { CandidatePort, IRemoteExplorerService, makeAddress, PORT_AUTO_FORWARD_SETTING, PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_OUTPUT, TunnelCloseReason, TunnelSource } from 'vs/workbench/services/remote/common/remoteExplorerService'; @@ -23,7 +23,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'v export class MainThreadTunnelService extends Disposable implements MainThreadTunnelServiceShape, PortAttributesProvider { private readonly _proxy: ExtHostTunnelServiceShape; private elevateionRetry: boolean = false; - private portsAttributesProviders: Map = new Map(); + private portsAttributesProviders: Map = new Map(); constructor( extHostContext: IExtHostContext, @@ -63,7 +63,7 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun } private _alreadyRegistered: boolean = false; - async $registerPortsAttributesProvider(selector: PortAttributesProviderSelector, providerHandle: number): Promise { + async $registerPortsAttributesProvider(selector: PortAttributesSelector, providerHandle: number): Promise { this.portsAttributesProviders.set(providerHandle, selector); if (!this._alreadyRegistered) { this.remoteExplorerService.tunnelModel.addAttributesProvider(this); @@ -85,9 +85,8 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun const selector = entry[1]; const portRange = selector.portRange; const portInRange = portRange ? ports.some(port => portRange[0] <= port && port < portRange[1]) : true; - const pidMatches = !selector.pid || (selector.pid === pid); const commandMatches = !selector.commandPattern || (commandLine && (commandLine.match(selector.commandPattern))); - return portInRange && pidMatches && commandMatches; + return portInRange && commandMatches; }).map(entry => entry[0]); if (appropriateHandles.length === 0) { diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index e6f76b539d0..00ff9e2cff7 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1077,7 +1077,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension, 'tunnels'); return extHostTunnelService.onDidChangeTunnels(listener, thisArg, disposables); }, - registerPortAttributesProvider: (portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: vscode.PortAttributesProvider) => { + registerPortAttributesProvider: (portSelector: vscode.PortAttributesSelector, provider: vscode.PortAttributesProvider) => { checkProposedApiEnabled(extension, 'portsAttributes'); return extHostTunnelService.registerPortsAttributesProvider(portSelector, provider); }, diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index a689fa33976..438fa03cd44 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1420,8 +1420,7 @@ export enum CandidatePortSource { Output = 2 } -export interface PortAttributesProviderSelector { - pid?: number; +export interface PortAttributesSelector { portRange?: [number, number]; commandPattern?: RegExp; } @@ -1435,7 +1434,7 @@ export interface MainThreadTunnelServiceShape extends IDisposable { $setCandidateFilter(): Promise; $onFoundNewCandidates(candidates: CandidatePort[]): Promise; $setCandidatePortSource(source: CandidatePortSource): Promise; - $registerPortsAttributesProvider(selector: PortAttributesProviderSelector, providerHandle: number): Promise; + $registerPortsAttributesProvider(selector: PortAttributesSelector, providerHandle: number): Promise; $unregisterPortsAttributesProvider(providerHandle: number): Promise; } diff --git a/src/vs/workbench/api/common/extHostTunnelService.ts b/src/vs/workbench/api/common/extHostTunnelService.ts index a6ad6135611..dfdfc5ab5a2 100644 --- a/src/vs/workbench/api/common/extHostTunnelService.ts +++ b/src/vs/workbench/api/common/extHostTunnelService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ExtHostTunnelServiceShape, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; +import { ExtHostTunnelServiceShape, PortAttributesSelector, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import * as vscode from 'vscode'; import { ProvidedPortAttributes, RemoteTunnel, TunnelCreationOptions, TunnelOptions, TunnelPrivacyId } from 'vs/platform/tunnel/common/tunnel'; @@ -48,7 +48,7 @@ export interface IExtHostTunnelService extends ExtHostTunnelServiceShape { getTunnels(): Promise; onDidChangeTunnels: vscode.Event; setTunnelFactory(provider: vscode.RemoteAuthorityResolver | undefined): Promise; - registerPortsAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: vscode.PortAttributesProvider): IDisposable; + registerPortsAttributesProvider(portSelector: PortAttributesSelector, provider: vscode.PortAttributesProvider): IDisposable; } export const IExtHostTunnelService = createDecorator('IExtHostTunnelService'); @@ -74,7 +74,7 @@ export class ExtHostTunnelService implements IExtHostTunnelService { async setTunnelFactory(provider: vscode.RemoteAuthorityResolver | undefined): Promise { return { dispose: () => { } }; } - registerPortsAttributesProvider(portSelector: { pid?: number; portRange?: [number, number] }, provider: vscode.PortAttributesProvider) { + registerPortsAttributesProvider(portSelector: PortAttributesSelector, provider: vscode.PortAttributesProvider) { return { dispose: () => { } }; } diff --git a/src/vs/workbench/api/node/extHostTunnelService.ts b/src/vs/workbench/api/node/extHostTunnelService.ts index 209c4623e92..ae3cf3568f8 100644 --- a/src/vs/workbench/api/node/extHostTunnelService.ts +++ b/src/vs/workbench/api/node/extHostTunnelService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { MainThreadTunnelServiceShape, MainContext, PortAttributesProviderSelector, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; +import { MainThreadTunnelServiceShape, MainContext, PortAttributesSelector, TunnelDto } from 'vs/workbench/api/common/extHost.protocol'; import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'; import type * as vscode from 'vscode'; import * as nls from 'vs/nls'; @@ -186,7 +186,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe private _initialCandidates: CandidatePort[] | undefined = undefined; private _providerHandleCounter: number = 0; - private _portAttributesProviders: Map = new Map(); + private _portAttributesProviders: Map = new Map(); constructor( @IExtHostRpcService extHostRpc: IExtHostRpcService, @@ -232,7 +232,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe return this._providerHandleCounter++; } - registerPortsAttributesProvider(portSelector: PortAttributesProviderSelector, provider: vscode.PortAttributesProvider): vscode.Disposable { + registerPortsAttributesProvider(portSelector: PortAttributesSelector, provider: vscode.PortAttributesProvider): vscode.Disposable { const providerHandle = this.nextPortAttributesProviderHandle(); this._portAttributesProviders.set(providerHandle, { selector: portSelector, provider }); diff --git a/src/vscode-dts/vscode.proposed.portsAttributes.d.ts b/src/vscode-dts/vscode.proposed.portsAttributes.d.ts index 6f07fe7aadf..cf130357ead 100644 --- a/src/vscode-dts/vscode.proposed.portsAttributes.d.ts +++ b/src/vscode-dts/vscode.proposed.portsAttributes.d.ts @@ -7,6 +7,9 @@ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/115616 @alexr00 + /** + * The action that should be taken when a port is discovered through automatic port forwarding discovery. + */ export enum PortAutoForwardAction { /** * Notify the user that the port is being forwarded. This is the default action. @@ -67,21 +70,16 @@ declare module 'vscode' { providePortAttributes(port: number, pid: number | undefined, commandLine: string | undefined, token: CancellationToken): ProviderResult; } - export interface PortAttributesProviderSelector { - /** - * TODO: @alexr00 no one is currently using this. Should we delete it? - * If your {@link PortAttributesProvider PortAttributesProvider} is registered after your process has started then already know the process id of port you are listening on. - * Specifying a pid will cause your provider to only be called for ports that match the pid. - */ - pid?: number; - + /** + * A selector that will be used to filter which {@link PortAttributesProvider} should be called for each port. + */ + export interface PortAttributesSelector { /** * Specifying a port range will cause your provider to only be called for ports within the range. */ portRange?: [number, number]; /** - * TODO: @alexr00 no one is currently using this. Should we delete it? * Specifying a command pattern will cause your provider to only be called for processes whose command line matches the pattern. */ commandPattern?: RegExp; @@ -100,6 +98,6 @@ declare module 'vscode' { * If you don't specify a port selector your provider will be called for every port, which will result in slower port forwarding for the user. * @param provider The {@link PortAttributesProvider PortAttributesProvider}. */ - export function registerPortAttributesProvider(portSelector: PortAttributesProviderSelector, provider: PortAttributesProvider): Disposable; + export function registerPortAttributesProvider(portSelector: PortAttributesSelector, provider: PortAttributesProvider): Disposable; } }