Skip to content

Handle sendKeyPress events for temporary integrated consoles #3951

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 2 commits into from
May 5, 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
119 changes: 0 additions & 119 deletions src/debugAdapter.ts

This file was deleted.

28 changes: 10 additions & 18 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { PowerShellProcess} from "../process";
import { SessionManager, SessionStatus } from "../session";
import Settings = require("../settings");
import utils = require("../utils");
import { NamedPipeDebugAdapter } from "../debugAdapter";
import { Logger } from "../logging";
import { LanguageClientConsumer } from "../languageClientConsumer";

Expand All @@ -37,20 +36,16 @@ export class DebugSessionFeature extends LanguageClientConsumer

createDebugAdapterDescriptor(
session: vscode.DebugSession,
_executable: vscode.DebugAdapterExecutable): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
_executable: vscode.DebugAdapterExecutable | undefined): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {

const sessionDetails = session.configuration.createTemporaryIntegratedConsole
? this.tempSessionDetails
: this.sessionManager.getSessionDetails();

// Establish connection before setting up the session
this.logger.writeVerbose(`Connecting to pipe: ${sessionDetails.debugServicePipeName}`);
this.logger.writeVerbose(`Debug configuration: ${JSON.stringify(session.configuration)}`);

const debugAdapter = new NamedPipeDebugAdapter(sessionDetails.debugServicePipeName, this.logger);
debugAdapter.start();

return new vscode.DebugAdapterInlineImplementation(debugAdapter);
return new vscode.DebugAdapterNamedPipeServer(sessionDetails.debugServicePipeName);
}

// tslint:disable-next-line:no-empty
Expand All @@ -60,19 +55,16 @@ export class DebugSessionFeature extends LanguageClientConsumer
public setLanguageClient(languageClient: LanguageClient) {
languageClient.onNotification(
StartDebuggerNotificationType,
() =>
// TODO: Use a named debug configuration.
vscode.debug.startDebugging(undefined, {
request: "launch",
type: "PowerShell",
name: "PowerShell: Interactive Session",
}));
// TODO: Use a named debug configuration.
() => vscode.debug.startDebugging(undefined, {
request: "launch",
type: "PowerShell",
name: "PowerShell: Interactive Session"
}));

languageClient.onNotification(
StopDebuggerNotificationType,
() =>
vscode.debug.stopDebugging(undefined)
);
() => vscode.debug.stopDebugging(undefined));
}

public async provideDebugConfigurations(
Expand Down Expand Up @@ -374,7 +366,7 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable {

const text = await vscode.window.showInputBox(options);
// When user cancel's the input box (by pressing Esc), the text value is undefined.
// Let's not blow away the previous settting.
// Let's not blow away the previous setting.
if (text !== undefined) {
this.context.workspaceState.update(powerShellDbgScriptArgsKey, text);
}
Expand Down
22 changes: 18 additions & 4 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ 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 @@ -273,6 +270,20 @@ export class SessionManager implements Middleware {
sessionPath,
sessionSettings);

// Similar to the regular integrated console, we need to send a key
// press to the process spawned for temporary integrated consoles when
// the server requests a cancellation os Console.ReadKey.
//
// TODO: There may be multiple sessions running in parallel, so we need
// to track a process per session, but that already isn't being done.
vscode.debug.onDidReceiveDebugSessionCustomEvent(
e => {
if (e.event === "powerShell/sendKeyPress") {
this.debugSessionProcess.sendKeyPress();
}
}
);

return this.debugSessionProcess;
}

Expand Down Expand Up @@ -797,7 +808,7 @@ export class SessionManager implements Middleware {
new SessionMenuItem(
"Restart Current Session",
() => {
// We pass in the display name so we guarentee that the session
// We pass in the display name so we guarantee that the session
// will be the same PowerShell.
this.restartSession(this.PowerShellExeDetails.displayName);
}),
Expand Down Expand Up @@ -828,6 +839,9 @@ class SessionMenuItem implements vscode.QuickPickItem {
}
}

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

export const PowerShellVersionRequestType =
new RequestType0<IPowerShellVersionDetails, void>(
"powerShell/getVersion");
Expand Down