Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b95667e

Browse files
Fix disposal of temporary console and event handler (#3953)
Fixes a bug where the first patch would register a new event handler every time, leading to multiple 'p's being sent. We currently only support one process at a time, and so this patch consolidates the process's and the event handler's disposal.
1 parent a13d87c commit b95667e

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

‎src/features/DebugSession.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
2525

2626
private sessionCount: number = 1;
2727
private tempDebugProcess: PowerShellProcess;
28+
private tempDebugEventHandler: vscode.Disposable;
2829
private tempSessionDetails: utils.IEditorServicesSessionDetails;
2930

3031
constructor(context: ExtensionContext, private sessionManager: SessionManager, private logger: Logger) {
@@ -313,18 +314,10 @@ export class DebugSessionFeature extends LanguageClientConsumer
313314
const sessionFilePath = utils.getDebugSessionFilePath();
314315

315316
if (config.createTemporaryIntegratedConsole) {
316-
if (this.tempDebugProcess) {
317-
this.tempDebugProcess.dispose();
318-
}
319-
320-
this.tempDebugProcess =
321-
this.sessionManager.createDebugSessionProcess(
322-
sessionFilePath,
323-
settings);
324-
317+
// TODO: This should be cleaned up to support multiple temporary consoles.
318+
this.tempDebugProcess = this.sessionManager.createDebugSessionProcess(sessionFilePath, settings);
325319
this.tempSessionDetails = await this.tempDebugProcess.start(`DebugSession-${this.sessionCount++}`);
326320
utils.writeSessionFile(sessionFilePath, this.tempSessionDetails);
327-
328321
} else {
329322
utils.writeSessionFile(sessionFilePath, this.sessionManager.getSessionDetails());
330323
}

‎src/session.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class SessionManager implements Middleware {
5050
private statusBarItem: vscode.StatusBarItem;
5151
private languageServerProcess: PowerShellProcess;
5252
private debugSessionProcess: PowerShellProcess;
53+
private debugEventHandler: vscode.Disposable;
5354
private versionDetails: IPowerShellVersionDetails;
5455
private registeredCommands: vscode.Disposable[] = [];
5556
private languageServerClient: LanguageClient = undefined;
@@ -228,9 +229,10 @@ export class SessionManager implements Middleware {
228229
this.languageServerClient = undefined;
229230
}
230231

231-
// Kill the PowerShell proceses we spawned
232+
// Kill the PowerShell process we spawned
232233
if (this.debugSessionProcess) {
233234
this.debugSessionProcess.dispose();
235+
this.debugEventHandler.dispose();
234236
}
235237
if (this.languageServerProcess) {
236238
this.languageServerProcess.dispose();
@@ -260,6 +262,15 @@ export class SessionManager implements Middleware {
260262
sessionPath: string,
261263
sessionSettings: Settings.ISettings): PowerShellProcess {
262264

265+
// NOTE: We only support one temporary integrated console at a time. To
266+
// support more, we need to track each separately, and tie the session
267+
// for the event handler to the right process (and dispose of the event
268+
// handler when the process is disposed).
269+
if (this.debugSessionProcess) {
270+
this.debugSessionProcess.dispose()
271+
this.debugEventHandler.dispose();
272+
}
273+
263274
this.debugSessionProcess =
264275
new PowerShellProcess(
265276
this.PowerShellExeDetails.exePath,
@@ -273,10 +284,7 @@ export class SessionManager implements Middleware {
273284
// Similar to the regular integrated console, we need to send a key
274285
// press to the process spawned for temporary integrated consoles when
275286
// 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(
287+
this.debugEventHandler = vscode.debug.onDidReceiveDebugSessionCustomEvent(
280288
e => {
281289
if (e.event === "powerShell/sendKeyPress") {
282290
this.debugSessionProcess.sendKeyPress();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /