Skip to content

Commit a13d87c

Browse files
Merge pull request #3951 from PowerShell/andschwa/fix-temp-console
Handle `sendKeyPress` events for temporary integrated consoles
2 parents 8c80df6 + f2d8cf1 commit a13d87c

File tree

3 files changed

+28
-141
lines changed

3 files changed

+28
-141
lines changed

src/debugAdapter.ts

-119
This file was deleted.

src/features/DebugSession.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { PowerShellProcess} from "../process";
1111
import { SessionManager, SessionStatus } from "../session";
1212
import Settings = require("../settings");
1313
import utils = require("../utils");
14-
import { NamedPipeDebugAdapter } from "../debugAdapter";
1514
import { Logger } from "../logging";
1615
import { LanguageClientConsumer } from "../languageClientConsumer";
1716

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

3837
createDebugAdapterDescriptor(
3938
session: vscode.DebugSession,
40-
_executable: vscode.DebugAdapterExecutable): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
39+
_executable: vscode.DebugAdapterExecutable | undefined): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
4140

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

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

50-
const debugAdapter = new NamedPipeDebugAdapter(sessionDetails.debugServicePipeName, this.logger);
51-
debugAdapter.start();
52-
53-
return new vscode.DebugAdapterInlineImplementation(debugAdapter);
48+
return new vscode.DebugAdapterNamedPipeServer(sessionDetails.debugServicePipeName);
5449
}
5550

5651
// tslint:disable-next-line:no-empty
@@ -60,19 +55,16 @@ export class DebugSessionFeature extends LanguageClientConsumer
6055
public setLanguageClient(languageClient: LanguageClient) {
6156
languageClient.onNotification(
6257
StartDebuggerNotificationType,
63-
() =>
64-
// TODO: Use a named debug configuration.
65-
vscode.debug.startDebugging(undefined, {
66-
request: "launch",
67-
type: "PowerShell",
68-
name: "PowerShell: Interactive Session",
69-
}));
58+
// TODO: Use a named debug configuration.
59+
() => vscode.debug.startDebugging(undefined, {
60+
request: "launch",
61+
type: "PowerShell",
62+
name: "PowerShell: Interactive Session"
63+
}));
7064

7165
languageClient.onNotification(
7266
StopDebuggerNotificationType,
73-
() =>
74-
vscode.debug.stopDebugging(undefined)
75-
);
67+
() => vscode.debug.stopDebugging(undefined));
7668
}
7769

7870
public async provideDebugConfigurations(
@@ -374,7 +366,7 @@ export class SpecifyScriptArgsFeature implements vscode.Disposable {
374366

375367
const text = await vscode.window.showInputBox(options);
376368
// When user cancel's the input box (by pressing Esc), the text value is undefined.
377-
// Let's not blow away the previous settting.
369+
// Let's not blow away the previous setting.
378370
if (text !== undefined) {
379371
this.context.workspaceState.update(powerShellDbgScriptArgsKey, text);
380372
}

src/session.ts

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

37-
export const SendKeyPressNotificationType =
38-
new NotificationType<void>("powerShell/sendKeyPress");
39-
4037
export class SessionManager implements Middleware {
4138
public HostName: string;
4239
public HostVersion: string;
@@ -273,6 +270,20 @@ export class SessionManager implements Middleware {
273270
sessionPath,
274271
sessionSettings);
275272

273+
// Similar to the regular integrated console, we need to send a key
274+
// press to the process spawned for temporary integrated consoles when
275+
// the server requests a cancellation os Console.ReadKey.
276+
//
277+
// TODO: There may be multiple sessions running in parallel, so we need
278+
// to track a process per session, but that already isn't being done.
279+
vscode.debug.onDidReceiveDebugSessionCustomEvent(
280+
e => {
281+
if (e.event === "powerShell/sendKeyPress") {
282+
this.debugSessionProcess.sendKeyPress();
283+
}
284+
}
285+
);
286+
276287
return this.debugSessionProcess;
277288
}
278289

@@ -797,7 +808,7 @@ export class SessionManager implements Middleware {
797808
new SessionMenuItem(
798809
"Restart Current Session",
799810
() => {
800-
// We pass in the display name so we guarentee that the session
811+
// We pass in the display name so we guarantee that the session
801812
// will be the same PowerShell.
802813
this.restartSession(this.PowerShellExeDetails.displayName);
803814
}),
@@ -828,6 +839,9 @@ class SessionMenuItem implements vscode.QuickPickItem {
828839
}
829840
}
830841

842+
export const SendKeyPressNotificationType =
843+
new NotificationType<void>("powerShell/sendKeyPress");
844+
831845
export const PowerShellVersionRequestType =
832846
new RequestType0<IPowerShellVersionDetails, void>(
833847
"powerShell/getVersion");

0 commit comments

Comments
 (0)