Skip to content

Commit

Permalink
Ensure Python Terminal Shell Integration setting is effective without…
Browse files Browse the repository at this point in the history
… reloading (#24826)

Resolves: #24373
  • Loading branch information
anthonykim1 authored Feb 18, 2025
1 parent 08e228d commit 2bcd557
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/client/terminals/pythonStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import { ExtensionContext, Uri } from 'vscode';
import * as path from 'path';
import { copy, createDirectory, getConfiguration } from '../common/vscodeApis/workspaceApis';
import { copy, createDirectory, getConfiguration, onDidChangeConfiguration } from '../common/vscodeApis/workspaceApis';
import { EXTENSION_ROOT_DIR } from '../constants';

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

Expand All @@ -25,3 +25,14 @@ export async function registerPythonStartup(context: ExtensionContext): Promise<
context.environmentVariableCollection.delete('PYTHONSTARTUP');
}
}

export async function registerPythonStartup(context: ExtensionContext): Promise<void> {
await applyPythonStartupSetting(context);
context.subscriptions.push(
onDidChangeConfiguration(async (e) => {
if (e.affectsConfiguration('python.terminal.shellIntegration.enabled')) {
await applyPythonStartupSetting(context);
}
}),
);
}
13 changes: 13 additions & 0 deletions src/test/terminals/shellIntegration/pythonStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TerminalLinkContext,
Terminal,
EventEmitter,
workspace,
} from 'vscode';
import { assert } from 'chai';
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
Expand All @@ -35,6 +36,7 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
globalEnvironmentVariableCollection = TypeMoq.Mock.ofType<GlobalEnvironmentVariableCollection>();
context.setup((c) => c.environmentVariableCollection).returns(() => globalEnvironmentVariableCollection.object);
context.setup((c) => c.storageUri).returns(() => Uri.parse('a'));
context.setup((c) => c.subscriptions).returns(() => []);

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

registerTerminalLinkProviderStub.restore();
});

test('Verify onDidChangeConfiguration is called when configuration changes', async () => {
const onDidChangeConfigurationSpy = sinon.spy(workspace, 'onDidChangeConfiguration');
pythonConfig.setup((p) => p.get('terminal.shellIntegration.enabled')).returns(() => true);

await registerPythonStartup(context.object);

assert.isTrue(onDidChangeConfigurationSpy.calledOnce);
onDidChangeConfigurationSpy.restore();
});

if (process.platform === 'darwin') {
test('Mac - Verify provideTerminalLinks returns links when context.line contains expectedNativeLink', () => {
const provider = new CustomTerminalLinkProvider();
Expand Down

0 comments on commit 2bcd557

Please sign in to comment.