Skip to content

Commit 44a490b

Browse files
authored
Update port attributes API (microsoft#182761)
Add doc updates and make selector a type. Part of microsoft#115616
1 parent b4a2a00 commit 44a490b

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,29 @@ declare module 'vscode' {
88
// https://github.com/microsoft/vscode/issues/115616 @alexr00
99

1010
export enum PortAutoForwardAction {
11+
/**
12+
* Notify the user that the port is being forwarded. This is the default action.
13+
*/
1114
Notify = 1,
15+
/**
16+
* Once the port is forwarded, open the browser to the forwarded port.
17+
*/
1218
OpenBrowser = 2,
19+
/**
20+
* Once the port is forwarded, open the preview browser to the forwarded port.
21+
*/
1322
OpenPreview = 3,
23+
/**
24+
* Forward the port silently.
25+
*/
1426
Silent = 4,
27+
/**
28+
* Do not forward the port.
29+
*/
1530
Ignore = 5,
31+
/**
32+
* Once the port is forwarded, open the browser to the forwarded port. Only open the browser the first time the port is forwarded in a session.
33+
*/
1634
OpenBrowserOnce = 6
1735
}
1836

@@ -49,20 +67,39 @@ declare module 'vscode' {
4967
providePortAttributes(port: number, pid: number | undefined, commandLine: string | undefined, token: CancellationToken): ProviderResult<PortAttributes>;
5068
}
5169

70+
export interface PortAttributesProviderSelector {
71+
/**
72+
* TODO: @alexr00 no one is currently using this. Should we delete it?
73+
* If your {@link PortAttributesProvider PortAttributesProvider} is registered after your process has started then already know the process id of port you are listening on.
74+
* Specifying a pid will cause your provider to only be called for ports that match the pid.
75+
*/
76+
pid?: number;
77+
78+
/**
79+
* Specifying a port range will cause your provider to only be called for ports within the range.
80+
*/
81+
portRange?: [number, number];
82+
83+
/**
84+
* TODO: @alexr00 no one is currently using this. Should we delete it?
85+
* Specifying a command pattern will cause your provider to only be called for processes whose command line matches the pattern.
86+
*/
87+
commandPattern?: RegExp;
88+
}
89+
5290
export namespace workspace {
5391
/**
5492
* If your extension listens on ports, consider registering a PortAttributesProvider to provide information
5593
* about the ports. For example, a debug extension may know about debug ports in it's debuggee. By providing
5694
* this information with a PortAttributesProvider the extension can tell the editor that these ports should be
5795
* ignored, since they don't need to be user facing.
5896
*
59-
* @param portSelector If registerPortAttributesProvider is called after you start your process then you may already
60-
* know the range of ports or the pid of your process. All properties of a the portSelector must be true for your
61-
* provider to get called.
62-
* 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.
64-
* @param provider The PortAttributesProvider
97+
* The results of the PortAttributesProvider are merged with the user setting `remote.portsAttributes`. If the values conflict, the user setting takes precedence.
98+
*
99+
* @param portSelector It is best practice to specify a port selector to avoid unnecessary calls to your provider.
100+
* 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.
101+
* @param provider The {@link PortAttributesProvider PortAttributesProvider}.
65102
*/
66-
export function registerPortAttributesProvider(portSelector: { pid?: number; portRange?: [number, number]; commandPattern?: RegExp }, provider: PortAttributesProvider): Disposable;
103+
export function registerPortAttributesProvider(portSelector: PortAttributesProviderSelector, provider: PortAttributesProvider): Disposable;
67104
}
68105
}

0 commit comments

Comments
 (0)