Skip to content

Commit 3f98265

Browse files
Fix automatic focus to temporary debug terminal (if it exists) (#4203)
This fixes the client so that if a temporary debug terminal is in use that it will be focused instead of the session terminal when debugging.
1 parent 4b9b447 commit 3f98265

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

src/features/DebugSession.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ export class DebugSessionFeature extends LanguageClientConsumer
225225
if (this.sessionManager.getSessionStatus() !== SessionStatus.Running) {
226226
await this.sessionManager.start();
227227
}
228-
// Create or show the Extension Terminal.
229-
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
228+
229+
// Create or show the debug terminal (either temporary or session).
230+
this.sessionManager.showDebugTerminal(true);
230231

231232
return config;
232233
}

src/features/PesterTests.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as path from "path";
55
import vscode = require("vscode");
6+
import { SessionManager } from "../session";
67
import Settings = require("../settings");
78
import utils = require("../utils");
89

@@ -16,7 +17,7 @@ export class PesterTestsFeature implements vscode.Disposable {
1617
private command: vscode.Disposable;
1718
private invokePesterStubScriptPath: string;
1819

19-
constructor() {
20+
constructor(private sessionManager: SessionManager) {
2021
this.invokePesterStubScriptPath = path.resolve(__dirname, "../modules/PowerShellEditorServices/InvokePesterStub.ps1");
2122

2223
// File context-menu command - Run Pester Tests
@@ -126,7 +127,7 @@ export class PesterTestsFeature implements vscode.Disposable {
126127
private async launch(launchConfig: vscode.DebugConfiguration): Promise<boolean> {
127128
// Create or show the interactive console
128129
// TODO: #367 Check if "newSession" mode is configured
129-
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
130+
this.sessionManager.showDebugTerminal(true);
130131

131132
// TODO: Update to handle multiple root workspaces.
132133
//

src/features/RunCode.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import * as path from "path";
54
import vscode = require("vscode");
65
import { SessionManager } from "../session";
76
import Settings = require("../settings");
8-
import utils = require("../utils");
97

108
enum LaunchType {
119
Debug,
@@ -41,7 +39,7 @@ export class RunCodeFeature implements vscode.Disposable {
4139
private async launch(launchConfig: string | vscode.DebugConfiguration) {
4240
// Create or show the interactive console
4341
// TODO: #367: Check if "newSession" mode is configured
44-
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
42+
this.sessionManager.showDebugTerminal(true);
4543

4644
// TODO: Update to handle multiple root workspaces.
4745
await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], launchConfig);

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
139139
new GenerateBugReportFeature(sessionManager),
140140
new ISECompatibilityFeature(),
141141
new OpenInISEFeature(),
142-
new PesterTestsFeature(),
142+
new PesterTestsFeature(sessionManager),
143143
new RunCodeFeature(sessionManager),
144144
new CodeActionsFeature(logger),
145145
new SpecifyScriptArgsFeature(context),

src/process.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
import cp = require("child_process");
5-
import * as semver from "semver";
65
import path = require("path");
76
import vscode = require("vscode");
87
import { Logger } from "./logging";
@@ -138,10 +137,8 @@ export class PowerShellProcess {
138137
return sessionDetails;
139138
}
140139

141-
public showConsole(preserveFocus: boolean) {
142-
if (this.consoleTerminal) {
143-
this.consoleTerminal.show(preserveFocus);
144-
}
140+
public showTerminal(preserveFocus?: boolean) {
141+
this.consoleTerminal?.show(preserveFocus);
145142
}
146143

147144
public dispose() {

src/session.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class SessionManager implements Middleware {
8888
private editorServicesArgs: string;
8989
private sessionStatus: SessionStatus = SessionStatus.NeverStarted;
9090
private suppressRestartPrompt: boolean;
91-
private focusConsoleOnExecute: boolean;
91+
private focusTerminalOnExecute: boolean;
9292
private platformDetails: IPlatformDetails;
9393
private languageClientConsumers: LanguageClientConsumer[] = [];
9494
private languageStatusItem: vscode.LanguageStatusItem;
@@ -188,7 +188,7 @@ export class SessionManager implements Middleware {
188188
this.platformDetails,
189189
this.sessionSettings.powerShellAdditionalExePaths);
190190

191-
this.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;
191+
this.focusTerminalOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;
192192

193193
this.createStatusBarItem();
194194

@@ -482,7 +482,7 @@ Type 'help' to get help.
482482
private async onConfigurationUpdated() {
483483
const settings = Settings.load();
484484

485-
this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute;
485+
this.focusTerminalOnExecute = settings.integratedConsole.focusConsoleOnExecute;
486486

487487
// Detect any setting changes that would affect the session
488488
if (!this.suppressRestartPrompt &&
@@ -508,7 +508,7 @@ Type 'help' to get help.
508508
vscode.commands.registerCommand(this.ShowSessionMenuCommandName, async () => { await this.showSessionMenu(); }),
509509
vscode.workspace.onDidChangeConfiguration(async () => { await this.onConfigurationUpdated(); }),
510510
vscode.commands.registerCommand(
511-
"PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionConsole(isExecute); }),
511+
"PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionTerminal(isExecute); }),
512512
vscode.commands.registerCommand(
513513
"PowerShell.WalkthroughTelemetry", (satisfaction: number) => {
514514
this.sendTelemetryEvent("powershellWalkthroughSatisfaction", null, { level: satisfaction });
@@ -795,12 +795,20 @@ Type 'help' to get help.
795795
await this.restartSession(exePath.displayName);
796796
}
797797

798-
private showSessionConsole(isExecute?: boolean) {
799-
if (this.languageServerProcess) {
800-
this.languageServerProcess.showConsole(isExecute && !this.focusConsoleOnExecute);
798+
// Shows the temp debug terminal if it exists, otherwise the session terminal.
799+
public showDebugTerminal(isExecute?: boolean) {
800+
if (this.debugSessionProcess) {
801+
this.debugSessionProcess.showTerminal(isExecute && !this.focusTerminalOnExecute);
802+
} else {
803+
this.languageServerProcess?.showTerminal(isExecute && !this.focusTerminalOnExecute)
801804
}
802805
}
803806

807+
// Always shows the session terminal.
808+
public showSessionTerminal(isExecute?: boolean) {
809+
this.languageServerProcess?.showTerminal(isExecute && !this.focusTerminalOnExecute);
810+
}
811+
804812
private async showSessionMenu() {
805813
const availablePowerShellExes = await this.powershellExeFinder.getAllAvailablePowerShellInstallations();
806814

0 commit comments

Comments
 (0)