Skip to content

Commit dc50906

Browse files
authored
Don't show activate button for task terminal (#1168)
Resolves: #27 need to update engine version probably after microsoft/vscode#292681 has been merged.
1 parent f124cb2 commit dc50906

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
"publisher": "ms-python",
77
"preview": true,
88
"engines": {
9-
"vscode": "^1.106.0"
9+
"vscode": "^1.110.0-20260204"
1010
},
1111
"categories": [
1212
"Other"
1313
],
1414
"enabledApiProposals": [
1515
"terminalShellEnv",
16-
"terminalDataWriteEvent"
16+
"terminalDataWriteEvent",
17+
"taskExecutionTerminal"
1718
],
1819
"capabilities": {
1920
"untrustedWorkspaces": {

src/features/terminal/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as path from 'path';
2-
import { Disposable, env, Terminal, TerminalOptions, Uri } from 'vscode';
2+
import { Disposable, env, tasks, Terminal, TerminalOptions, Uri } from 'vscode';
33
import { PythonEnvironment, PythonProject, PythonProjectEnvironmentApi, PythonProjectGetterApi } from '../../api';
44
import { timeout } from '../../common/utils/asyncUtils';
55
import { createSimpleDebounce } from '../../common/utils/debounce';
@@ -129,8 +129,9 @@ function detectsCommonPromptPattern(terminalData: string): boolean {
129129
}
130130

131131
export function isTaskTerminal(terminal: Terminal): boolean {
132-
// TODO: Need API for core for this https://github.com/microsoft/vscode/issues/234440
133-
return terminal.name.toLowerCase().includes('task');
132+
// Use tasks.taskExecutions API to check if terminal is associated with a task
133+
// See: https://github.com/microsoft/vscode/issues/234440
134+
return tasks.taskExecutions.some((execution) => execution.terminal === terminal);
134135
}
135136

136137
export function getTerminalCwd(terminal: Terminal): string | undefined {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as assert from 'assert';
2+
import * as sinon from 'sinon';
3+
import { Terminal } from 'vscode';
4+
import { PythonEnvironment } from '../../../api';
5+
import * as commandApi from '../../../common/command.api';
6+
import * as activation from '../../../features/common/activation';
7+
import { setActivateMenuButtonContext } from '../../../features/terminal/activateMenuButton';
8+
import * as utils from '../../../features/terminal/utils';
9+
10+
suite('Terminal - Activate Menu Button', () => {
11+
let executeCommandStub: sinon.SinonStub;
12+
let isTaskTerminalStub: sinon.SinonStub;
13+
let isActivatableEnvironmentStub: sinon.SinonStub;
14+
15+
const mockTerminal = { name: 'test-terminal' } as Terminal;
16+
const mockEnv = {} as PythonEnvironment; // Stubbed, so no properties needed
17+
18+
setup(() => {
19+
executeCommandStub = sinon.stub(commandApi, 'executeCommand').resolves();
20+
isTaskTerminalStub = sinon.stub(utils, 'isTaskTerminal');
21+
isActivatableEnvironmentStub = sinon.stub(activation, 'isActivatableEnvironment');
22+
});
23+
24+
teardown(() => {
25+
sinon.restore();
26+
});
27+
28+
test('should show activate icon when isTaskTerminal returns false', async () => {
29+
// Arrange: terminal is NOT a task terminal, env is activatable
30+
isTaskTerminalStub.returns(false);
31+
isActivatableEnvironmentStub.returns(true);
32+
33+
// Act
34+
await setActivateMenuButtonContext(mockTerminal, mockEnv);
35+
36+
// Assert: icon should be shown (pythonTerminalActivation = true)
37+
assert.ok(
38+
executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', true),
39+
'Should set pythonTerminalActivation to true for non-task terminal',
40+
);
41+
});
42+
43+
test('should hide activate icon when isTaskTerminal returns true', async () => {
44+
// Arrange: terminal IS a task terminal (even if env is activatable)
45+
isTaskTerminalStub.returns(true);
46+
isActivatableEnvironmentStub.returns(true);
47+
48+
// Act
49+
await setActivateMenuButtonContext(mockTerminal, mockEnv);
50+
51+
// Assert: icon should be hidden (pythonTerminalActivation = false)
52+
assert.ok(
53+
executeCommandStub.calledWith('setContext', 'pythonTerminalActivation', false),
54+
'Should set pythonTerminalActivation to false for task terminal',
55+
);
56+
});
57+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// https://github.com/microsoft/vscode/issues/234440
7+
8+
declare module 'vscode' {
9+
export interface TaskExecution {
10+
/**
11+
* The terminal associated with this task execution, if any.
12+
*/
13+
terminal?: Terminal;
14+
}
15+
}

0 commit comments

Comments
 (0)