Skip to content

Fix automatic focus to temporary debug terminal (if it exists) #4203

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 1 commit into from
Oct 10, 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
5 changes: 3 additions & 2 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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
Expand Down Expand Up @@ -126,7 +127,7 @@ export class PesterTestsFeature implements vscode.Disposable {
private async launch(launchConfig: vscode.DebugConfiguration): Promise<boolean> {
// 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.
//
Expand Down
4 changes: 1 addition & 3 deletions src/features/RunCode.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
new GenerateBugReportFeature(sessionManager),
new ISECompatibilityFeature(),
new OpenInISEFeature(),
new PesterTestsFeature(),
new PesterTestsFeature(sessionManager),
new RunCodeFeature(sessionManager),
new CodeActionsFeature(logger),
new SpecifyScriptArgsFeature(context),
Expand Down
7 changes: 2 additions & 5 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

import cp = require("child_process");
import * as semver from "semver";
import path = require("path");
import vscode = require("vscode");
import { Logger } from "./logging";
Expand Down Expand Up @@ -138,10 +137,8 @@ export class PowerShellProcess {
return sessionDetails;
}

public showConsole(preserveFocus: boolean) {
if (this.consoleTerminal) {
this.consoleTerminal.show(preserveFocus);
}
public showTerminal(preserveFocus?: boolean) {
this.consoleTerminal?.show(preserveFocus);
}

public dispose() {
Expand Down
22 changes: 15 additions & 7 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class SessionManager implements Middleware {
private editorServicesArgs: string;
private sessionStatus: SessionStatus = SessionStatus.NeverStarted;
private suppressRestartPrompt: boolean;
private focusConsoleOnExecute: boolean;
private focusTerminalOnExecute: boolean;
private platformDetails: IPlatformDetails;
private languageClientConsumers: LanguageClientConsumer[] = [];
private languageStatusItem: vscode.LanguageStatusItem;
Expand Down Expand Up @@ -188,7 +188,7 @@ export class SessionManager implements Middleware {
this.platformDetails,
this.sessionSettings.powerShellAdditionalExePaths);

this.focusConsoleOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;
this.focusTerminalOnExecute = this.sessionSettings.integratedConsole.focusConsoleOnExecute;

this.createStatusBarItem();

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

this.focusConsoleOnExecute = settings.integratedConsole.focusConsoleOnExecute;
this.focusTerminalOnExecute = settings.integratedConsole.focusConsoleOnExecute;

// Detect any setting changes that would affect the session
if (!this.suppressRestartPrompt &&
Expand All @@ -508,7 +508,7 @@ Type 'help' to get help.
vscode.commands.registerCommand(this.ShowSessionMenuCommandName, async () => { 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 });
Expand Down Expand Up @@ -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();

Expand Down