| 10 | |
| 11 | @injectable() |
| 12 | export class JsDebugPortAttributesProvider |
| 13 | implements IExtensionContribution, PortAttributesProvider |
| 14 | { |
| 15 | /** Cache of used ports (#1092) */ |
| 16 | private cachedResolutions: string[] = new Array(16).fill(''); |
| 17 | /** Index counter for the next cached resolution index in the list */ |
| 18 | private cachedResolutionIndex = 0; |
| 19 | |
| 20 | constructor(@inject(IPortLeaseTracker) private readonly leaseTracker: IPortLeaseTracker) {} |
| 21 | |
| 22 | /** |
| 23 | * @inheritdoc |
| 24 | */ |
| 25 | public register(context: ExtensionContext) { |
| 26 | if (typeof workspace.registerPortAttributesProvider === 'function') { |
| 27 | context.subscriptions.push( |
| 28 | workspace.registerPortAttributesProvider( |
| 29 | { portRange: [DefaultJsDebugPorts.Min, DefaultJsDebugPorts.Max] }, |
| 30 | this, |
| 31 | ), |
| 32 | ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @inheritdoc |
| 38 | */ |
| 39 | public async providePortAttributes({ port, pid }: { port: number; pid?: number }) { |
| 40 | if (pid && this.cachedResolutions.includes(`${port}:${pid}`)) { |
| 41 | return { port, autoForwardAction: PortAutoForwardAction.Ignore }; |
| 42 | } |
| 43 | |
| 44 | if (!(await this.leaseTracker.isRegistered(port))) { |
| 45 | return undefined; |
| 46 | } |
| 47 | |
| 48 | if (pid) { |
| 49 | const index = this.cachedResolutionIndex++ % this.cachedResolutions.length; |
| 50 | this.cachedResolutions[index] = `${port}:${pid}`; |
| 51 | } |
| 52 | |
| 53 | return { port, autoForwardAction: PortAutoForwardAction.Ignore }; |
| 54 | } |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected