From 01ab50b9294a9d64f62eb9a121ba1d823666e7b3 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Fri, 22 Apr 2022 12:35:33 +0300 Subject: [PATCH] Improve pause connection (#147318) --- .../vscode-test-resolver/src/extension.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/extensions/vscode-test-resolver/src/extension.ts b/extensions/vscode-test-resolver/src/extension.ts index b74d79c0cc6..9f6fc9efc18 100644 --- a/extensions/vscode-test-resolver/src/extension.ts +++ b/extensions/vscode-test-resolver/src/extension.ts @@ -24,7 +24,13 @@ let outputChannel: vscode.OutputChannel; export function activate(context: vscode.ExtensionContext) { + let connectionPaused = false; + let connectionPausedEvent = new vscode.EventEmitter(); + function doResolve(_authority: string, progress: vscode.Progress<{ message?: string; increment?: number }>): Promise { + if (connectionPaused) { + throw vscode.RemoteAuthorityResolverError.TemporarilyNotAvailable('Not available right now'); + } const connectionToken = String(crypto.randomInt(0xffffffffff)); // eslint-disable-next-line no-async-promise-executor @@ -151,8 +157,8 @@ export function activate(context: vscode.ExtensionContext) { let remoteReady = true, localReady = true; const remoteSocket = net.createConnection({ port: serverAddr.port }); - let isDisconnected = connectionPaused; - connectionPausedEvent.event(_ => { + let isDisconnected = false; + const handleConnectionPause = () => { let newIsDisconnected = connectionPaused; if (isDisconnected !== newIsDisconnected) { outputChannel.appendLine(`Connection state: ${newIsDisconnected ? 'open' : 'paused'}`); @@ -175,7 +181,10 @@ export function activate(context: vscode.ExtensionContext) { } } } - }); + }; + + connectionPausedEvent.event(_ => handleConnectionPause()); + handleConnectionPause(); proxySocket.on('data', (data) => { remoteReady = remoteSocket.write(data); @@ -251,9 +260,6 @@ export function activate(context: vscode.ExtensionContext) { }); } - let connectionPaused = false; - let connectionPausedEvent = new vscode.EventEmitter(); - const authorityResolverDisposable = vscode.workspace.registerRemoteAuthorityResolver('test', { async getCanonicalURI(uri: vscode.Uri): Promise { return vscode.Uri.file(uri.path);