From e2fa9e74ec202de8f9e8ea95f15db2c19d195c5f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 7 Apr 2022 11:56:50 -0700 Subject: [PATCH] Add `sendKeyPress` notification used to "cancel" `Console.ReadKey` --- src/process.ts | 4 ++++ src/session.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/process.ts b/src/process.ts index 8409c8d26c..10a20e2d57 100644 --- a/src/process.ts +++ b/src/process.ts @@ -163,6 +163,10 @@ export class PowerShellProcess { } } + public sendKeyPress() { + this.consoleTerminal.sendText("\0", false); + } + private logTerminalPid(pid: number, exeName: string) { this.log.write(`${exeName} PID: ${pid}`); } diff --git a/src/session.ts b/src/session.ts index f1a9ca5a70..6ac6169f5c 100644 --- a/src/session.ts +++ b/src/session.ts @@ -34,6 +34,9 @@ export enum SessionStatus { Failed, } +export const SendKeyPressNotificationType = + new NotificationType("powerShell/sendKeyPress"); + export class SessionManager implements Middleware { public HostName: string; public HostVersion: string; @@ -605,6 +608,14 @@ export class SessionManager implements Middleware { this.languageServerClient.onNotification( RunspaceChangedEventType, (runspaceDetails) => { this.setStatusBarVersionString(runspaceDetails); }); + + // NOTE: This fixes a quirk where PSES has a thread stuck on + // Console.ReadKey, since it's not cancellable. On + // "cancellation" the server asks us to send pretend to + // press a key, thus mitigating all the quirk. + this.languageServerClient.onNotification( + SendKeyPressNotificationType, + () => { this.languageServerProcess.sendKeyPress(); }); }, (reason) => { this.setSessionFailure("Could not start language service: ", reason);