Skip to content

Commit f255e02

Browse files
author
Kartik Raj
authored
Call out that env name may not show in terminal activation notification (#21897)
Closes #21887
1 parent 782d5b1 commit f255e02

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/client/common/utils/localize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export namespace Interpreters {
199199
export const activatingTerminals = l10n.t('Reactivating terminals...');
200200
export const activateTerminalDescription = l10n.t('Activated environment for');
201201
export const terminalEnvVarCollectionPrompt = l10n.t(
202-
'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).',
202+
'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).',
203203
);
204204
export const activatedCondaEnvLaunch = l10n.t(
205205
'We noticed VS Code was launched from an activated conda environment, would you like to select it?',

src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
IDisposableRegistry,
1010
IExperimentService,
1111
IPersistentStateFactory,
12+
Resource,
1213
} from '../../common/types';
1314
import { Common, Interpreters } from '../../common/utils/localize';
1415
import { IExtensionSingleActivationService } from '../../activation/types';
1516
import { ITerminalEnvVarCollectionService } from './types';
1617
import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers';
18+
import { IInterpreterService } from '../contracts';
1719

1820
export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY';
1921

@@ -30,6 +32,7 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
3032
@inject(ITerminalEnvVarCollectionService)
3133
private readonly terminalEnvVarCollectionService: ITerminalEnvVarCollectionService,
3234
@inject(IConfigurationService) private readonly configurationService: IConfigurationService,
35+
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
3336
@inject(IExperimentService) private readonly experimentService: IExperimentService,
3437
) {}
3538

@@ -52,12 +55,12 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
5255
// No need to show notification if terminal prompt already indicates when env is activated.
5356
return;
5457
}
55-
await this.notifyUsers();
58+
await this.notifyUsers(resource);
5659
}),
5760
);
5861
}
5962

60-
private async notifyUsers(): Promise<void> {
63+
private async notifyUsers(resource: Resource): Promise<void> {
6164
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState(
6265
terminalEnvCollectionPromptKey,
6366
true,
@@ -66,8 +69,10 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
6669
return;
6770
}
6871
const prompts = [Common.doNotShowAgain];
72+
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
73+
const terminalPromptName = interpreter?.envName ? ` (${interpreter.envName})` : '';
6974
const selection = await this.appShell.showInformationMessage(
70-
Interpreters.terminalEnvVarCollectionPrompt,
75+
Interpreters.terminalEnvVarCollectionPrompt.format(terminalPromptName),
7176
...prompts,
7277
);
7378
if (!selection) {

src/test/interpreters/activation/terminalEnvVarCollectionPrompt.unit.test.ts

+24-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { ITerminalEnvVarCollectionService } from '../../../client/interpreter/ac
1818
import { Common, Interpreters } from '../../../client/common/utils/localize';
1919
import { TerminalEnvVarActivation } from '../../../client/common/experiments/groups';
2020
import { sleep } from '../../core';
21+
import { IInterpreterService } from '../../../client/interpreter/contracts';
22+
import { PythonEnvironment } from '../../../client/pythonEnvironments/info';
2123

2224
suite('Terminal Environment Variable Collection Prompt', () => {
2325
let shell: IApplicationShell;
@@ -30,12 +32,18 @@ suite('Terminal Environment Variable Collection Prompt', () => {
3032
let terminalEventEmitter: EventEmitter<Terminal>;
3133
let notificationEnabled: IPersistentState<boolean>;
3234
let configurationService: IConfigurationService;
35+
let interpreterService: IInterpreterService;
3336
const prompts = [Common.doNotShowAgain];
34-
const message = Interpreters.terminalEnvVarCollectionPrompt;
37+
const envName = 'env';
38+
const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(` (${envName})`);
3539

3640
setup(async () => {
3741
shell = mock<IApplicationShell>();
3842
terminalManager = mock<ITerminalManager>();
43+
interpreterService = mock<IInterpreterService>();
44+
when(interpreterService.getActiveInterpreter(anything())).thenResolve(({
45+
envName,
46+
} as unknown) as PythonEnvironment);
3947
experimentService = mock<IExperimentService>();
4048
activeResourceService = mock<IActiveResourceService>();
4149
persistentStateFactory = mock<IPersistentStateFactory>();
@@ -61,6 +69,7 @@ suite('Terminal Environment Variable Collection Prompt', () => {
6169
instance(activeResourceService),
6270
instance(terminalEnvVarCollectionService),
6371
instance(configurationService),
72+
instance(interpreterService),
6473
instance(experimentService),
6574
);
6675
});
@@ -74,13 +83,13 @@ suite('Terminal Environment Variable Collection Prompt', () => {
7483
} as unknown) as Terminal;
7584
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
7685
when(notificationEnabled.value).thenReturn(true);
77-
when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined);
86+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
7887

7988
await terminalEnvVarCollectionPrompt.activate();
8089
terminalEventEmitter.fire(terminal);
8190
await sleep(1);
8291

83-
verify(shell.showInformationMessage(message, ...prompts)).once();
92+
verify(shell.showInformationMessage(expectedMessage, ...prompts)).once();
8493
});
8594

8695
test('Do not show notification if automatic terminal activation is turned off', async () => {
@@ -98,13 +107,13 @@ suite('Terminal Environment Variable Collection Prompt', () => {
98107
} as unknown) as Terminal;
99108
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
100109
when(notificationEnabled.value).thenReturn(true);
101-
when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined);
110+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
102111

103112
await terminalEnvVarCollectionPrompt.activate();
104113
terminalEventEmitter.fire(terminal);
105114
await sleep(1);
106115

107-
verify(shell.showInformationMessage(message, ...prompts)).never();
116+
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
108117
});
109118

110119
test('When not in experiment, do not show notification for the same', async () => {
@@ -116,15 +125,15 @@ suite('Terminal Environment Variable Collection Prompt', () => {
116125
} as unknown) as Terminal;
117126
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
118127
when(notificationEnabled.value).thenReturn(true);
119-
when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined);
128+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
120129

121130
reset(experimentService);
122131
when(experimentService.inExperimentSync(TerminalEnvVarActivation.experiment)).thenReturn(false);
123132
await terminalEnvVarCollectionPrompt.activate();
124133
terminalEventEmitter.fire(terminal);
125134
await sleep(1);
126135

127-
verify(shell.showInformationMessage(message, ...prompts)).never();
136+
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
128137
});
129138

130139
test('Do not show notification if notification is disabled', async () => {
@@ -136,13 +145,13 @@ suite('Terminal Environment Variable Collection Prompt', () => {
136145
} as unknown) as Terminal;
137146
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
138147
when(notificationEnabled.value).thenReturn(false);
139-
when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined);
148+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
140149

141150
await terminalEnvVarCollectionPrompt.activate();
142151
terminalEventEmitter.fire(terminal);
143152
await sleep(1);
144153

145-
verify(shell.showInformationMessage(message, ...prompts)).never();
154+
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
146155
});
147156

148157
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', () => {
154163
} as unknown) as Terminal;
155164
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(true);
156165
when(notificationEnabled.value).thenReturn(true);
157-
when(shell.showInformationMessage(message, ...prompts)).thenResolve(undefined);
166+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined);
158167

159168
await terminalEnvVarCollectionPrompt.activate();
160169
terminalEventEmitter.fire(terminal);
161170
await sleep(1);
162171

163-
verify(shell.showInformationMessage(message, ...prompts)).never();
172+
verify(shell.showInformationMessage(expectedMessage, ...prompts)).never();
164173
});
165174

166175
test("Disable notification if `Don't show again` is clicked", async () => {
@@ -173,7 +182,9 @@ suite('Terminal Environment Variable Collection Prompt', () => {
173182
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
174183
when(notificationEnabled.value).thenReturn(true);
175184
when(notificationEnabled.updateValue(false)).thenResolve();
176-
when(shell.showInformationMessage(message, ...prompts)).thenReturn(Promise.resolve(Common.doNotShowAgain));
185+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn(
186+
Promise.resolve(Common.doNotShowAgain),
187+
);
177188

178189
await terminalEnvVarCollectionPrompt.activate();
179190
terminalEventEmitter.fire(terminal);
@@ -192,7 +203,7 @@ suite('Terminal Environment Variable Collection Prompt', () => {
192203
when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false);
193204
when(notificationEnabled.value).thenReturn(true);
194205
when(notificationEnabled.updateValue(false)).thenResolve();
195-
when(shell.showInformationMessage(message, ...prompts)).thenReturn(Promise.resolve(undefined));
206+
when(shell.showInformationMessage(expectedMessage, ...prompts)).thenReturn(Promise.resolve(undefined));
196207

197208
await terminalEnvVarCollectionPrompt.activate();
198209
terminalEventEmitter.fire(terminal);

0 commit comments

Comments
 (0)