Skip to content

Commit 2bcd557

Browse files
authored
Ensure Python Terminal Shell Integration setting is effective without reloading (#24826)
Resolves: #24373
1 parent 08e228d commit 2bcd557

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/client/terminals/pythonStartup.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import { ExtensionContext, Uri } from 'vscode';
55
import * as path from 'path';
6-
import { copy, createDirectory, getConfiguration } from '../common/vscodeApis/workspaceApis';
6+
import { copy, createDirectory, getConfiguration, onDidChangeConfiguration } from '../common/vscodeApis/workspaceApis';
77
import { EXTENSION_ROOT_DIR } from '../constants';
88

9-
export async function registerPythonStartup(context: ExtensionContext): Promise<void> {
9+
async function applyPythonStartupSetting(context: ExtensionContext): Promise<void> {
1010
const config = getConfiguration('python');
1111
const pythonrcSetting = config.get<boolean>('terminal.shellIntegration.enabled');
1212

@@ -25,3 +25,14 @@ export async function registerPythonStartup(context: ExtensionContext): Promise<
2525
context.environmentVariableCollection.delete('PYTHONSTARTUP');
2626
}
2727
}
28+
29+
export async function registerPythonStartup(context: ExtensionContext): Promise<void> {
30+
await applyPythonStartupSetting(context);
31+
context.subscriptions.push(
32+
onDidChangeConfiguration(async (e) => {
33+
if (e.affectsConfiguration('python.terminal.shellIntegration.enabled')) {
34+
await applyPythonStartupSetting(context);
35+
}
36+
}),
37+
);
38+
}

src/test/terminals/shellIntegration/pythonStartup.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
TerminalLinkContext,
1313
Terminal,
1414
EventEmitter,
15+
workspace,
1516
} from 'vscode';
1617
import { assert } from 'chai';
1718
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
@@ -35,6 +36,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
3536
globalEnvironmentVariableCollection = TypeMoq.Mock.ofType<GlobalEnvironmentVariableCollection>();
3637
context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object);
3738
context.setup((c) => c.storageUri).returns(() => Uri.parse('a'));
39+
context.setup((c) => c.subscriptions).returns(() => []);
3840

3941
globalEnvironmentVariableCollection
4042
.setup((c) => c.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny()))
@@ -146,6 +148,17 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
146148

147149
registerTerminalLinkProviderStub.restore();
148150
});
151+
152+
test('Verify onDidChangeConfiguration is called when configuration changes', async () => {
153+
const onDidChangeConfigurationSpy = sinon.spy(workspace, 'onDidChangeConfiguration');
154+
pythonConfig.setup((p) => p.get('terminal.shellIntegration.enabled')).returns(() => true);
155+
156+
await registerPythonStartup(context.object);
157+
158+
assert.isTrue(onDidChangeConfigurationSpy.calledOnce);
159+
onDidChangeConfigurationSpy.restore();
160+
});
161+
149162
if (process.platform === 'darwin') {
150163
test('Mac - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => {
151164
const provider = new CustomTerminalLinkProvider();

0 commit comments

Comments
 (0)