Skip to content

Commit 7a9294c

Browse files
author
Kartik Raj
authored
1 parent 44f5bf7 commit 7a9294c

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { inject, injectable } from 'inversify';
5-
import { Uri } from 'vscode';
5+
import { Uri, l10n } from 'vscode';
66
import * as path from 'path';
77
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types';
88
import {
@@ -91,10 +91,10 @@ function getPromptName(interpreter?: PythonEnvironment) {
9191
return '';
9292
}
9393
if (interpreter.envName) {
94-
return ` "(${interpreter.envName})"`;
94+
return `, ${l10n.t('i.e')} "(${interpreter.envName})"`;
9595
}
9696
if (interpreter.envPath) {
97-
return ` "(${path.basename(interpreter.envPath)})"`;
97+
return `, ${l10n.t('i.e')} "(${path.basename(interpreter.envPath)})"`;
9898
}
9999
return '';
100100
}

src/client/interpreter/activation/terminalEnvVarCollectionService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) {
345345
return undefined;
346346
}
347347
if (interpreter.envName) {
348+
if (interpreter.envName === 'base') {
349+
// If conda base environment is selected, it can lead to "(base)" appearing twice if we return the env name.
350+
return undefined;
351+
}
348352
return `(${interpreter.envName}) `;
349353
}
350354
if (interpreter.envPath) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import { mock, when, anything, instance, verify, reset } from 'ts-mockito';
7-
import { EventEmitter, Terminal, Uri } from 'vscode';
7+
import { EventEmitter, Terminal, Uri, l10n } from 'vscode';
88
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../../client/common/application/types';
99
import {
1010
IConfigurationService,
@@ -35,7 +35,7 @@ suite('Terminal Environment Variable Collection Prompt', () => {
3535
let interpreterService: IInterpreterService;
3636
const prompts = [Common.doNotShowAgain];
3737
const envName = 'env';
38-
const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(` "(${envName})"`);
38+
const expectedMessage = Interpreters.terminalEnvVarCollectionPrompt.format(`, ${l10n.t('i.e')} "(${envName})"`);
3939

4040
setup(async () => {
4141
shell = mock<IApplicationShell>();

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,34 @@ suite('Terminal Environment Variable Collection Service', () => {
349349
expect(result).to.equal(true);
350350
});
351351

352+
test('Correct track that prompt was not set for non-Windows where PS1 is not set but env name is base', async () => {
353+
when(platform.osType).thenReturn(OSType.Linux);
354+
const envVars: NodeJS.ProcessEnv = { CONDA_PREFIX: 'prefix/to/conda', ...process.env };
355+
const ps1Shell = 'zsh';
356+
const resource = Uri.file('a');
357+
const workspaceFolder: WorkspaceFolder = {
358+
uri: Uri.file('workspacePath'),
359+
name: 'workspace1',
360+
index: 0,
361+
};
362+
when(interpreterService.getActiveInterpreter(resource)).thenResolve(({
363+
type: PythonEnvType.Conda,
364+
envName: 'base',
365+
envPath: 'prefix/to/conda',
366+
} as unknown) as PythonEnvironment);
367+
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
368+
when(
369+
environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell),
370+
).thenResolve(envVars);
371+
when(collection.replace(anything(), anything(), anything())).thenReturn();
372+
373+
await terminalEnvVarCollectionService._applyCollection(resource, ps1Shell);
374+
375+
const result = terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource);
376+
377+
expect(result).to.equal(false);
378+
});
379+
352380
test('Correct track that prompt was not set for non-Windows fish where PS1 is not set', async () => {
353381
when(platform.osType).thenReturn(OSType.Linux);
354382
const envVars: NodeJS.ProcessEnv = { CONDA_PREFIX: 'prefix/to/conda', ...process.env };

0 commit comments

Comments
 (0)