Skip to content

Commit 3b971b2

Browse files
committed
Add sendKeyPress notification used to "cancel" Console.ReadKey
1 parent 525cae6 commit 3b971b2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: src/process.ts

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export class PowerShellProcess {
163163
}
164164
}
165165

166+
public sendKeyPress() {
167+
this.consoleTerminal.sendText("\0", false);
168+
}
169+
166170
private logTerminalPid(pid: number, exeName: string) {
167171
this.log.write(`${exeName} PID: ${pid}`);
168172
}

Diff for: src/session.ts

+11
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export enum SessionStatus {
3434
Failed,
3535
}
3636

37+
export const SendKeyPressNotificationType =
38+
new NotificationType<void>("powerShell/sendKeyPress");
39+
3740
export class SessionManager implements Middleware {
3841
public HostName: string;
3942
public HostVersion: string;
@@ -605,6 +608,14 @@ export class SessionManager implements Middleware {
605608
this.languageServerClient.onNotification(
606609
RunspaceChangedEventType,
607610
(runspaceDetails) => { this.setStatusBarVersionString(runspaceDetails); });
611+
612+
// NOTE: This fixes a quirk where PSES has a thread stuck on
613+
// Console.ReadKey, since it's not cancellable. On
614+
// "cancellation" the server asks us to send pretend to
615+
// press a key, thus mitigating all the quirk.
616+
this.languageServerClient.onNotification(
617+
SendKeyPressNotificationType,
618+
() => { this.languageServerProcess.sendKeyPress(); });
608619
},
609620
(reason) => {
610621
this.setSessionFailure("Could not start language service: ", reason);

0 commit comments

Comments
 (0)