Skip to content

Add sendKeyPress notification used to "cancel" Console.ReadKey #3911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand Down
11 changes: 11 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export enum SessionStatus {
Failed,
}

export const SendKeyPressNotificationType =
new NotificationType<void>("powerShell/sendKeyPress");

export class SessionManager implements Middleware {
public HostName: string;
public HostVersion: string;
Expand Down Expand Up @@ -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);
Expand Down