From fcccc85ff97242b32b02fd02993c11312285da4b Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 21 Jan 2021 16:23:33 +0100 Subject: [PATCH] Add more to test resolver tunnel factory and fix port filtering --- .../vscode-test-resolver/src/extension.ts | 21 ++++++++----------- .../api/node/extHostTunnelService.ts | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/extensions/vscode-test-resolver/src/extension.ts b/extensions/vscode-test-resolver/src/extension.ts index 1b9f7da7243..cec710d5c56 100644 --- a/extensions/vscode-test-resolver/src/extension.ts +++ b/extensions/vscode-test-resolver/src/extension.ts @@ -338,27 +338,19 @@ function getConfiguration(id: string): T | undefined { return vscode.workspace.getConfiguration('testresolver').get(id); } -const allTunnels: Map = new Map(); +const remoteServers: number[] = []; async function showCandidatePort(_host: string, port: number, _detail: string): Promise { - return !Array.from(allTunnels.values()).find(value => { - if (typeof value.localAddress === 'string') { - return true; - } else { - return value.localAddress.port === port; - } - }); + return remoteServers.includes(port) || port === 100; } async function tunnelFactory(tunnelOptions: vscode.TunnelOptions, tunnelCreationOptions: vscode.TunnelCreationOptions): Promise { + outputChannel.appendLine(`Tunnel factory request: Remote ${tunnelOptions.remoteAddress.port} -> local ${tunnelOptions.localAddressPort}`); if (tunnelCreationOptions.elevationRequired) { await vscode.window.showInformationMessage('This is a fake elevation message. A real resolver would show a native elevation prompt.', { modal: true }, 'Ok'); } - const tunnel = await createTunnelService(); - - allTunnels.set(tunnel.remoteAddress.port, tunnel); - return tunnel; + return createTunnelService(); function newTunnel(localAddress: { host: string, port: number }) { const onDidDispose: vscode.EventEmitter = new vscode.EventEmitter(); @@ -416,6 +408,7 @@ function runHTTPTestServer(port: number): vscode.Disposable { res.writeHead(200); res.end(`Hello, World from test server running on port ${port}!`); }); + remoteServers.push(port); server.listen(port); const message = `Opened HTTP server on http://localhost:${port}`; console.log(message); @@ -423,6 +416,10 @@ function runHTTPTestServer(port: number): vscode.Disposable { return { dispose: () => { server.close(); + const index = remoteServers.indexOf(port); + if (index !== -1) { + remoteServers.splice(index, 1); + } } }; } diff --git a/src/vs/workbench/api/node/extHostTunnelService.ts b/src/vs/workbench/api/node/extHostTunnelService.ts index 8060d619e26..b7a05876859 100644 --- a/src/vs/workbench/api/node/extHostTunnelService.ts +++ b/src/vs/workbench/api/node/extHostTunnelService.ts @@ -259,7 +259,8 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe } async $applyCandidateFilter(candidates: CandidatePort[]): Promise { - return Promise.all(candidates.filter(candidate => this._showCandidatePort(candidate.host, candidate.port, candidate.detail))); + const filter = await Promise.all(candidates.map(candidate => this._showCandidatePort(candidate.host, candidate.port, candidate.detail))); + return candidates.filter((candidate, index) => filter[index]); } async findCandidatePorts(): Promise {