Skip to content

Commit 44cc589

Browse files
committed
Do not activate for task terminal.
1 parent 12a7df6 commit 44cc589

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/common/tasks.apis.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { Task, TaskExecution, tasks } from 'vscode';
2-
1+
import { Disposable, Task, TaskExecution, TaskProcessStartEvent, tasks } from 'vscode';
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
33
export async function executeTask(task: Task): Promise<TaskExecution> {
44
return tasks.executeTask(task);
55
}
6+
7+
export function onDidStartTaskProcess(
8+
listener: (e: TaskProcessStartEvent) => any,
9+
thisArgs?: any,
10+
disposables?: Disposable[],
11+
): Disposable {
12+
return tasks.onDidStartTaskProcess(listener, thisArgs, disposables);
13+
}

src/features/terminal/terminalManager.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Disposable, EventEmitter, ProgressLocation, Terminal, TerminalOptions,
44
import { PythonEnvironment, PythonEnvironmentApi, PythonProject, PythonTerminalCreateOptions } from '../../api';
55
import { ActivationStrings } from '../../common/localize';
66
import { traceInfo, traceVerbose } from '../../common/logging';
7+
import { onDidStartTaskProcess } from '../../common/tasks.apis';
78
import {
89
createTerminal,
910
onDidChangeWindowState,
@@ -68,6 +69,7 @@ export interface TerminalManager
6869
export class TerminalManagerImpl implements TerminalManager {
6970
private disposables: Disposable[] = [];
7071
private skipActivationOnOpen = new Set<Terminal>();
72+
private taskProcessIds = new Set<number>();
7173
private shellSetup: Map<string, boolean> = new Map<string, boolean>();
7274

7375
private onTerminalOpenedEmitter = new EventEmitter<Terminal>();
@@ -96,10 +98,22 @@ export class TerminalManagerImpl implements TerminalManager {
9698
onDidCloseTerminal((t: Terminal) => {
9799
this.onTerminalClosedEmitter.fire(t);
98100
}),
101+
onDidStartTaskProcess((tp) => {
102+
this.taskProcessIds.add(tp.processId);
103+
traceVerbose(`Task process started with PID: ${tp.processId}`);
104+
}),
99105
this.onTerminalOpened(async (t) => {
100106
if (this.skipActivationOnOpen.has(t) || (t.creationOptions as TerminalOptions)?.hideFromUser) {
101107
return;
102108
}
109+
// Wait briefly to allow onDidStartTaskProcess to fire
110+
await new Promise((resolve) => setTimeout(resolve, 1000));
111+
const terminalProcessId = await t.processId;
112+
if (terminalProcessId && this.taskProcessIds.has(terminalProcessId)) {
113+
traceVerbose(`Skipping activation for task terminal with PID: ${terminalProcessId}`);
114+
return;
115+
}
116+
103117
let env = this.ta.getEnvironment(t);
104118
if (!env) {
105119
const api = await getPythonApi();
@@ -109,8 +123,13 @@ export class TerminalManagerImpl implements TerminalManager {
109123
await this.autoActivateOnTerminalOpen(t, env);
110124
}
111125
}),
112-
this.onTerminalClosed((t) => {
126+
this.onTerminalClosed(async (t) => {
113127
this.skipActivationOnOpen.delete(t);
128+
const terminalProcessId = await t.processId;
129+
if (terminalProcessId && this.taskProcessIds.has(terminalProcessId)) {
130+
this.taskProcessIds.delete(terminalProcessId);
131+
traceVerbose(`Removed task process ID ${terminalProcessId} for closed terminal`);
132+
}
114133
}),
115134
this.ta.onDidChangeTerminalActivationState((e) => {
116135
this.onDidChangeTerminalActivationStateEmitter.fire(e);

0 commit comments

Comments
 (0)