Skip to content

Commit 1236c13

Browse files
authored
Ports attributes API updates (microsoft#182617)
* Ports attributes API updates Part of microsoft#115616 * Remove port number from attributes API
1 parent 9233de8 commit 1236c13

File tree

7 files changed

+29
-22
lines changed

7 files changed

+29
-22
lines changed

src/vs/workbench/api/browser/mainThreadTunnelService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class MainThreadTunnelService extends Disposable implements MainThreadTun
8686
const portRange = selector.portRange;
8787
const portInRange = portRange ? ports.some(port => portRange[0] <= port && port < portRange[1]) : true;
8888
const pidMatches = !selector.pid || (selector.pid === pid);
89-
const commandMatches = !selector.commandMatcher || (commandLine && (commandLine.match(selector.commandMatcher)));
89+
const commandMatches = !selector.commandPattern || (commandLine && (commandLine.match(selector.commandPattern)));
9090
return portInRange && pidMatches && commandMatches;
9191
}).map(entry => entry[0]);
9292

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
10711071
checkProposedApiEnabled(extension, 'tunnels');
10721072
return extHostTunnelService.onDidChangeTunnels(listener, thisArg, disposables);
10731073
},
1074-
registerPortAttributesProvider: (portSelector: { pid?: number; portRange?: [number, number]; commandMatcher?: RegExp }, provider: vscode.PortAttributesProvider) => {
1074+
registerPortAttributesProvider: (portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: vscode.PortAttributesProvider) => {
10751075
checkProposedApiEnabled(extension, 'portsAttributes');
10761076
return extHostTunnelService.registerPortsAttributesProvider(portSelector, provider);
10771077
},

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ export enum CandidatePortSource {
14001400
export interface PortAttributesProviderSelector {
14011401
pid?: number;
14021402
portRange?: [number, number];
1403-
commandMatcher?: RegExp;
1403+
commandPattern?: RegExp;
14041404
}
14051405

14061406
export interface MainThreadTunnelServiceShape extends IDisposable {

src/vs/workbench/api/common/extHostTunnelService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
4848
getTunnels(): Promise<vscode.TunnelDescription[]>;
4949
onDidChangeTunnels: vscode.Event<void>;
5050
setTunnelFactory(provider: vscode.RemoteAuthorityResolver | undefined): Promise<IDisposable>;
51-
registerPortsAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandMatcher?: RegExp }, provider: vscode.PortAttributesProvider): IDisposable;
51+
registerPortsAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: vscode.PortAttributesProvider): IDisposable;
5252
}
5353

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

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,15 +3834,16 @@ export class LinkedEditingRanges {
38343834

38353835
//#region ports
38363836
export class PortAttributes {
3837-
private _port: number;
38383837
private _autoForwardAction: PortAutoForwardAction;
3839-
constructor(port: number, autoForwardAction: PortAutoForwardAction) {
3840-
this._port = port;
3841-
this._autoForwardAction = autoForwardAction;
3842-
}
38433838

3844-
get port(): number {
3845-
return this._port;
3839+
constructor(autoForwardAction: PortAutoForwardAction);
3840+
constructor(port: number, autoForwardAction: PortAutoForwardAction);
3841+
constructor(portOrAction: number | PortAutoForwardAction, autoForwardAction?: PortAutoForwardAction) {
3842+
if (typeof portOrAction === 'number') {
3843+
this._autoForwardAction = autoForwardAction!;
3844+
} else {
3845+
this._autoForwardAction = portOrAction;
3846+
}
38463847
}
38473848

38483849
get autoForwardAction(): PortAutoForwardAction {

src/vs/workbench/api/node/extHostTunnelService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,22 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
244244
}
245245

246246
async $providePortAttributes(handles: number[], ports: number[], pid: number | undefined, commandline: string | undefined, cancellationToken: vscode.CancellationToken): Promise<ProvidedPortAttributes[]> {
247-
const providedAttributes: vscode.ProviderResult<vscode.PortAttributes>[] = [];
247+
const providedAttributes: { providedAttributes: vscode.PortAttributes | null | undefined; port: number }[] = [];
248248
for (const handle of handles) {
249249
const provider = this._portAttributesProviders.get(handle);
250250
if (!provider) {
251251
return [];
252252
}
253253
providedAttributes.push(...(await Promise.all(ports.map(async (port) => {
254-
return provider.provider.providePortAttributes(port, pid, commandline, cancellationToken);
254+
return { providedAttributes: (await provider.provider.providePortAttributes(port, pid, commandline, cancellationToken)), port };
255255
}))));
256256
}
257257

258-
const allAttributes = <vscode.PortAttributes[]>providedAttributes.filter(attribute => !!attribute);
258+
const allAttributes = <{ providedAttributes: vscode.PortAttributes; port: number }[]>providedAttributes.filter(attribute => !!attribute.providedAttributes);
259259

260260
return (allAttributes.length > 0) ? allAttributes.map(attributes => {
261261
return {
262-
autoForwardAction: <ProvidedOnAutoForward><unknown>attributes.autoForwardAction,
262+
autoForwardAction: <ProvidedOnAutoForward><unknown>attributes.providedAttributes.autoForwardAction,
263263
port: attributes.port
264264
};
265265
}) : [];

src/vscode-dts/vscode.proposed.portsAttributes.d.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,30 @@ declare module 'vscode' {
1616
OpenBrowserOnce = 6
1717
}
1818

19+
/**
20+
* The attributes that a forwarded port can have.
21+
*/
1922
export class PortAttributes {
20-
/**
21-
* The port number associated with this this set of attributes.
22-
*/
23-
port: number;
24-
2523
/**
2624
* The action to be taken when this port is detected for auto forwarding.
2725
*/
2826
autoForwardAction: PortAutoForwardAction;
2927

28+
/**
29+
* @deprecated
30+
*/
31+
constructor(port: number, autoForwardAction: PortAutoForwardAction);
3032
/**
3133
* Creates a new PortAttributes object
3234
* @param port the port number
3335
* @param autoForwardAction the action to take when this port is detected
3436
*/
35-
constructor(port: number, autoForwardAction: PortAutoForwardAction);
37+
constructor(autoForwardAction: PortAutoForwardAction);
3638
}
3739

40+
/**
41+
* A provider of port attributes. Port attributes are used to determine what action should be taken when a port is discovered.
42+
*/
3843
export interface PortAttributesProvider {
3944
/**
4045
* Provides attributes for the given port. For ports that your extension doesn't know about, simply
@@ -55,8 +60,9 @@ declare module 'vscode' {
5560
* know the range of ports or the pid of your process. All properties of a the portSelector must be true for your
5661
* provider to get called.
5762
* The `portRange` is start inclusive and end exclusive.
63+
* The `commandPattern` is a regular expression that will be matched against the command line of the process.
5864
* @param provider The PortAttributesProvider
5965
*/
60-
export function registerPortAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandMatcher?: RegExp }, provider: PortAttributesProvider): Disposable;
66+
export function registerPortAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: PortAttributesProvider): Disposable;
6167
}
6268
}

0 commit comments

Comments
 (0)