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
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
Loading