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);