diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 4401cab56176..eb8e94a85a52 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -199,7 +199,7 @@ export namespace Interpreters { export const activatingTerminals = l10n.t('Reactivating terminals...'); export const activateTerminalDescription = l10n.t('Activated environment for'); export const terminalEnvVarCollectionPrompt = l10n.t( - 'The Python extension automatically activates all terminals using the selected environment. You can hover over the terminal tab to see more information about the activation. [Learn more](https://aka.ms/vscodePythonTerminalActivation).', + 'The Python extension automatically activates all terminals using the selected environment, even when the name of the environment{0} is not present in the terminal prompt. [Learn more](https://aka.ms/vscodePythonTerminalActivation).', ); export const activatedCondaEnvLaunch = l10n.t( 'We noticed VS Code was launched from an activated conda environment, would you like to select it?', diff --git a/src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts b/src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts index 7833f34ce2fb..8b7850514874 100644 --- a/src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts +++ b/src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts @@ -9,11 +9,13 @@ import { IDisposableRegistry, IExperimentService, IPersistentStateFactory, + Resource, } from '../../common/types'; import { Common, Interpreters } from '../../common/utils/localize'; import { IExtensionSingleActivationService } from '../../activation/types'; import { ITerminalEnvVarCollectionService } from './types'; import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers'; +import { IInterpreterService } from '../contracts'; export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY'; @@ -30,6 +32,7 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio @inject(ITerminalEnvVarCollectionService) private readonly terminalEnvVarCollectionService: ITerminalEnvVarCollectionService, @inject(IConfigurationService) private readonly configurationService: IConfigurationService, + @inject(IInterpreterService) private readonly interpreterService: IInterpreterService, @inject(IExperimentService) private readonly experimentService: IExperimentService, ) {} @@ -52,12 +55,12 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio // No need to show notification if terminal prompt already indicates when env is activated. return; } - await this.notifyUsers(); + await this.notifyUsers(resource); }), ); } - private async notifyUsers(): Promise { + private async notifyUsers(resource: Resource): Promise { const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState( terminalEnvCollectionPromptKey, true, @@ -66,8 +69,10 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio return; } const prompts = [Common.doNotShowAgain]; + const interpreter = await this.interpreterService.getActiveInterpreter(resource); + const terminalPromptName = interpreter?.envName ? ` (${interpreter.envName})` : ''; const selection = await this.appShell.showInformationMessage( - Interpreters.terminalEnvVarCollectionPrompt, + Interpreters.terminalEnvVarCollectionPrompt.format(terminalPromptName), ...prompts, ); if (!selection) { diff --git a/src/test/interpreters/activation/terminalEnvVarCollectionPrompt.unit.test.ts b/src/test/interpreters/activation/terminalEnvVarCollectionPrompt.unit.test.ts index 8edaa00dcf73..e1bc2d171226 100644 --- a/src/test/interpreters/activation/terminalEnvVarCollectionPrompt.unit.test.ts +++ b/src/test/interpreters/activation/terminalEnvVarCollectionPrompt.unit.test.ts @@ -18,6 +18,8 @@ import { ITerminalEnvVarCollectionService } from '../../../client/interpreter/ac import { Common, Interpreters } from '../../../client/common/utils/localize'; import { TerminalEnvVarActivation } from '../../../client/common/experiments/groups'; import { sleep } from '../../core'; +import { IInterpreterService } from '../../../client/interpreter/contracts'; +import { PythonEnvironment } from '../../../client/pythonEnvironments/info'; suite('Terminal Environment Variable Collection Prompt', () => { let shell: IApplicationShell; @@ -30,12 +32,18 @@ suite('Terminal Environment Variable Collection Prompt', () => { let terminalEventEmitter: EventEmitter; let notificationEnabled: IPersistentState; let configurationService: IConfigurationService; + let interpreterService: IInterpreterService; const prompts = [Common.doNotShowAgain]; - const message = Interpreters.terminalEnvVarCollectionPrompt; + const envName = 'env'; + const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(` (${envName})`); setup(async () => { shell = mock(); terminalManager = mock(); + interpreterService = mock(); + when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + envName, + } as unknown) as PythonEnvironment); experimentService = mock(); activeResourceService = mock(); persistentStateFactory = mock(); @@ -61,6 +69,7 @@ suite('Terminal Environment Variable Collection Prompt', () => { instance(activeResourceService), instance(terminalEnvVarCollectionService), instance(configurationService), + instance(interpreterService), instance(experimentService), ); }); @@ -74,13 +83,13 @@ suite('Terminal Environment Variable Collection Prompt', () => { } as unknown) as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); - when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal); await sleep(1); - verify(shell.showInformationMessage(message, ...prompts)).once(); + verify(shell.showInformationMessage(expectedMessage, ...prompts)).once(); }); test('Do not show notification if automatic terminal activation is turned off', async () => { @@ -98,13 +107,13 @@ suite('Terminal Environment Variable Collection Prompt', () => { } as unknown) as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); - when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal); await sleep(1); - verify(shell.showInformationMessage(message, ...prompts)).never(); + verify(shell.showInformationMessage(expectedMessage, ...prompts)).never(); }); test('When not in experiment, do not show notification for the same', async () => { @@ -116,7 +125,7 @@ suite('Terminal Environment Variable Collection Prompt', () => { } as unknown) as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); - when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); reset(experimentService); when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(false); @@ -124,7 +133,7 @@ suite('Terminal Environment Variable Collection Prompt', () => { terminalEventEmitter.fire(terminal); await sleep(1); - verify(shell.showInformationMessage(message, ...prompts)).never(); + verify(shell.showInformationMessage(expectedMessage, ...prompts)).never(); }); test('Do not show notification if notification is disabled', async () => { @@ -136,13 +145,13 @@ suite('Terminal Environment Variable Collection Prompt', () => { } as unknown) as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(false); - when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal); await sleep(1); - verify(shell.showInformationMessage(message, ...prompts)).never(); + verify(shell.showInformationMessage(expectedMessage, ...prompts)).never(); }); test('Do not show notification when a new terminal is opened for which there is prompt set', async () => { @@ -154,13 +163,13 @@ suite('Terminal Environment Variable Collection Prompt', () => { } as unknown) as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(true); when(notificationEnabled.value).thenReturn(true); - when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal); await sleep(1); - verify(shell.showInformationMessage(message, ...prompts)).never(); + verify(shell.showInformationMessage(expectedMessage, ...prompts)).never(); }); test("Disable notification if `Don't show again` is clicked", async () => { @@ -173,7 +182,9 @@ suite('Terminal Environment Variable Collection Prompt', () => { when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(notificationEnabled.updateValue(false)).thenResolve(); - when(shell.showInformationMessage(message, ...prompts)).thenReturn(Promise.resolve(Common.doNotShowAgain)); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn( + Promise.resolve(Common.doNotShowAgain), + ); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal); @@ -192,7 +203,7 @@ suite('Terminal Environment Variable Collection Prompt', () => { when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(notificationEnabled.updateValue(false)).thenResolve(); - when(shell.showInformationMessage(message, ...prompts)).thenReturn(Promise.resolve(undefined)); + when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn(Promise.resolve(undefined)); await terminalEnvVarCollectionPrompt.activate(); terminalEventEmitter.fire(terminal);