Skip to content
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"publisher": "ms-python",
"preview": true,
"engines": {
"vscode": "^1.106.0"
"vscode": "^1.110.0-20260204"
},
"categories": [
"Other"
],
"enabledApiProposals": [
"terminalShellEnv",
"terminalDataWriteEvent"
"terminalDataWriteEvent",
"taskExecutionTerminal"
],
"capabilities": {
"untrustedWorkspaces": {
Expand Down
7 changes: 4 additions & 3 deletions src/features/terminal/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
57 changes: 57 additions & 0 deletions src/test/features/terminal/activateMenuButton.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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',
);
});
});
15 changes: 15 additions & 0 deletions src/vscode.proposed.taskExecutionTerminal.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}