From 1cb09dd9f2e60fcb52332e200333d06193b049df Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 3 Feb 2026 13:42:28 -0800 Subject: [PATCH 1/3] Don't show activate button for task terminal --- package.json | 5 +- src/features/terminal/utils.ts | 7 ++- .../terminal/activateMenuButton.unit.test.ts | 57 +++++++++++++++++++ ...vscode.proposed.taskExecutionTerminal.d.ts | 15 +++++ 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 src/test/features/terminal/activateMenuButton.unit.test.ts create mode 100644 src/vscode.proposed.taskExecutionTerminal.d.ts diff --git a/package.json b/package.json index d423d204..cc4c6533 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,15 @@ "publisher": "ms-python", "preview": true, "engines": { - "vscode": "^1.106.0" + "vscode": "^1.106.0" // Need new engine after distro update }, "categories": [ "Other" ], "enabledApiProposals": [ "terminalShellEnv", - "terminalDataWriteEvent" + "terminalDataWriteEvent", + "taskExecutionTerminal" ], "capabilities": { "untrustedWorkspaces": { diff --git a/src/features/terminal/utils.ts b/src/features/terminal/utils.ts index 83744808..d279a11e 100644 --- a/src/features/terminal/utils.ts +++ b/src/features/terminal/utils.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { Disposable, env, Terminal, TerminalOptions, Uri } from 'vscode'; +import { Disposable, env, tasks, Terminal, TerminalOptions, Uri } from 'vscode'; import { PythonEnvironment, PythonProject, PythonProjectEnvironmentApi, PythonProjectGetterApi } from '../../api'; import { timeout } from '../../common/utils/asyncUtils'; import { createSimpleDebounce } from '../../common/utils/debounce'; @@ -129,8 +129,9 @@ function detectsCommonPromptPattern(terminalData: string): boolean { } export function isTaskTerminal(terminal: Terminal): boolean { - // TODO: Need API for core for this https://github.com/microsoft/vscode/issues/234440 - return terminal.name.toLowerCase().includes('task'); + // Use tasks.taskExecutions API to check if terminal is associated with a task + // See: https://github.com/microsoft/vscode/issues/234440 + return tasks.taskExecutions.some((execution) => execution.terminal === terminal); } export function getTerminalCwd(terminal: Terminal): string | undefined { diff --git a/src/test/features/terminal/activateMenuButton.unit.test.ts b/src/test/features/terminal/activateMenuButton.unit.test.ts new file mode 100644 index 00000000..07c3fb84 --- /dev/null +++ b/src/test/features/terminal/activateMenuButton.unit.test.ts @@ -0,0 +1,57 @@ +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import { Terminal } from 'vscode'; +import { PythonEnvironment } from '../../../api'; +import * as commandApi from '../../../common/command.api'; +import * as activation from '../../../features/common/activation'; +import { setActivateMenuButtonContext } from '../../../features/terminal/activateMenuButton'; +import * as utils from '../../../features/terminal/utils'; + +suite('Terminal - Activate Menu Button', () => { + let executeCommandStub: sinon.SinonStub; + let isTaskTerminalStub: sinon.SinonStub; + let isActivatableEnvironmentStub: sinon.SinonStub; + + const mockTerminal = { name: 'test-terminal' } as Terminal; + const mockEnv = {} as PythonEnvironment; // Stubbed, so no properties needed + + setup(() => { + executeCommandStub = sinon.stub(commandApi, 'executeCommand').resolves(); + isTaskTerminalStub = sinon.stub(utils, 'isTaskTerminal'); + isActivatableEnvironmentStub = sinon.stub(activation, 'isActivatableEnvironment'); + }); + + teardown(() => { + sinon.restore(); + }); + + test('should show activate icon when isTaskTerminal returns false', async () => { + // Arrange: terminal is NOT a task terminal, env is activatable + isTaskTerminalStub.returns(false); + isActivatableEnvironmentStub.returns(true); + + // Act + await setActivateMenuButtonContext(mockTerminal, mockEnv); + + // Assert: icon should be shown (pythonTerminalActivation = true) + assert.ok( + executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', true), + 'Should set pythonTerminalActivation to true for non-task terminal', + ); + }); + + test('should hide activate icon when isTaskTerminal returns true', async () => { + // Arrange: terminal IS a task terminal (even if env is activatable) + isTaskTerminalStub.returns(true); + isActivatableEnvironmentStub.returns(true); + + // Act + await setActivateMenuButtonContext(mockTerminal, mockEnv); + + // Assert: icon should be hidden (pythonTerminalActivation = false) + assert.ok( + executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', false), + 'Should set pythonTerminalActivation to false for task terminal', + ); + }); +}); diff --git a/src/vscode.proposed.taskExecutionTerminal.d.ts b/src/vscode.proposed.taskExecutionTerminal.d.ts new file mode 100644 index 00000000..549a9b12 --- /dev/null +++ b/src/vscode.proposed.taskExecutionTerminal.d.ts @@ -0,0 +1,15 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +// https://github.com/microsoft/vscode/issues/234440 + +declare module 'vscode' { + export interface TaskExecution { + /** + * The terminal associated with this task execution, if any. + */ + terminal?: Terminal; + } +} From c633e86e97c0fc2cb463d4252f84ff4312d1ea36 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 3 Feb 2026 14:01:42 -0800 Subject: [PATCH 2/3] Merge tmr to avoid proposed api err --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55c0b83b..005b9f6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "webpack-cli": "^5.1.1" }, "engines": { - "vscode": "^1.106.0" + "vscode": "^1.109.0-20260204" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index cc4c6533..bf010f60 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "publisher": "ms-python", "preview": true, "engines": { - "vscode": "^1.106.0" // Need new engine after distro update + "vscode": "^1.109.0-20260204" }, "categories": [ "Other" From a7259638a95fc0c1fcaab9efb26e4a5f4a5bc8d6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 4 Feb 2026 12:37:49 -0800 Subject: [PATCH 3/3] correct version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 005b9f6b..42751388 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "webpack-cli": "^5.1.1" }, "engines": { - "vscode": "^1.109.0-20260204" + "vscode": "^1.110.0-20260204" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index bf010f60..9d14c779 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "publisher": "ms-python", "preview": true, "engines": { - "vscode": "^1.109.0-20260204" + "vscode": "^1.110.0-20260204" }, "categories": [ "Other"