From 5ec9c1560398273dc84c1fe751e2fd76e1e341ab Mon Sep 17 00:00:00 2001 From: Andy Jordan Date: Mon, 10 Oct 2022 12:48:48 -0700 Subject: [PATCH] Fix automatic focus to temporary debug terminal (if it exists) 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. --- src/features/DebugSession.ts | 5 +++-- src/features/PesterTests.ts | 5 +++-- src/features/RunCode.ts | 4 +--- src/main.ts | 2 +- src/process.ts | 7 ++----- src/session.ts | 22 +++++++++++++++------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index e9cc0db3ab..e10bbd78e1 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -225,8 +225,9 @@ export class DebugSessionFeature extends LanguageClientConsumer if (this.sessionManager.getSessionStatus() !== SessionStatus.Running) { await this.sessionManager.start(); } - // Create or show the Extension Terminal. - vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); + + // Create or show the debug terminal (either temporary or session). + this.sessionManager.showDebugTerminal(true); return config; } diff --git a/src/features/PesterTests.ts b/src/features/PesterTests.ts index ec48743183..7cda274f1a 100644 --- a/src/features/PesterTests.ts +++ b/src/features/PesterTests.ts @@ -3,6 +3,7 @@ import * as path from "path"; import vscode = require("vscode"); +import { SessionManager } from "../session"; import Settings = require("../settings"); import utils = require("../utils"); @@ -16,7 +17,7 @@ export class PesterTestsFeature implements vscode.Disposable { private command: vscode.Disposable; private invokePesterStubScriptPath: string; - constructor() { + constructor(private sessionManager: SessionManager) { this.invokePesterStubScriptPath = path.resolve(__dirname, "../modules/PowerShellEditorServices/InvokePesterStub.ps1"); // File context-menu command - Run Pester Tests @@ -126,7 +127,7 @@ export class PesterTestsFeature implements vscode.Disposable { private async launch(launchConfig: vscode.DebugConfiguration): Promise { // Create or show the interactive console // TODO: #367 Check if "newSession" mode is configured - await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); + this.sessionManager.showDebugTerminal(true); // TODO: Update to handle multiple root workspaces. // diff --git a/src/features/RunCode.ts b/src/features/RunCode.ts index 83f8c78473..db1a8546b3 100644 --- a/src/features/RunCode.ts +++ b/src/features/RunCode.ts @@ -1,11 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import * as path from "path"; import vscode = require("vscode"); import { SessionManager } from "../session"; import Settings = require("../settings"); -import utils = require("../utils"); enum LaunchType { Debug, @@ -41,7 +39,7 @@ export class RunCodeFeature implements vscode.Disposable { private async launch(launchConfig: string | vscode.DebugConfiguration) { // Create or show the interactive console // TODO: #367: Check if "newSession" mode is configured - await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true); + this.sessionManager.showDebugTerminal(true); // TODO: Update to handle multiple root workspaces. await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], launchConfig); diff --git a/src/main.ts b/src/main.ts index eaccd6e405..c35e92cc60 100644 --- a/src/main.ts +++ b/src/main.ts @@ -139,7 +139,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { await this.showSessionMenu(); }), vscode.workspace.onDidChangeConfiguration(async () => { await this.onConfigurationUpdated(); }), vscode.commands.registerCommand( - "PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionConsole(isExecute); }), + "PowerShell.ShowSessionConsole", (isExecute?: boolean) => { this.showSessionTerminal(isExecute); }), vscode.commands.registerCommand( "PowerShell.WalkthroughTelemetry", (satisfaction: number) => { this.sendTelemetryEvent("powershellWalkthroughSatisfaction", null, { level: satisfaction }); @@ -795,12 +795,20 @@ Type 'help' to get help. await this.restartSession(exePath.displayName); } - private showSessionConsole(isExecute?: boolean) { - if (this.languageServerProcess) { - this.languageServerProcess.showConsole(isExecute && !this.focusConsoleOnExecute); + // Shows the temp debug terminal if it exists, otherwise the session terminal. + public showDebugTerminal(isExecute?: boolean) { + if (this.debugSessionProcess) { + this.debugSessionProcess.showTerminal(isExecute && !this.focusTerminalOnExecute); + } else { + this.languageServerProcess?.showTerminal(isExecute && !this.focusTerminalOnExecute) } } + // Always shows the session terminal. + public showSessionTerminal(isExecute?: boolean) { + this.languageServerProcess?.showTerminal(isExecute && !this.focusTerminalOnExecute); + } + private async showSessionMenu() { const availablePowerShellExes = await this.powershellExeFinder.getAllAvailablePowerShellInstallations();