Skip to content

Commit

Permalink
Apply feedback for terminal activation prompt (microsoft#21905)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored and anthonykim1 committed Sep 12, 2023
1 parent 6c5fc2a commit c1e9b1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { Uri, l10n } from 'vscode';
import * as path from 'path';
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types';
import {
Expand Down Expand Up @@ -91,10 +91,10 @@ function getPromptName(interpreter?: PythonEnvironment) {
return '';
}
if (interpreter.envName) {
return ` "(${interpreter.envName})"`;
return `, ${l10n.t('i.e')} "(${interpreter.envName})"`;
}
if (interpreter.envPath) {
return ` "(${path.basename(interpreter.envPath)})"`;
return `, ${l10n.t('i.e')} "(${path.basename(interpreter.envPath)})"`;
}
return '';
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) {
return undefined;
}
if (interpreter.envName) {
if (interpreter.envName === 'base') {
// If conda base environment is selected, it can lead to "(base)" appearing twice if we return the env name.
return undefined;
}
return `(${interpreter.envName}) `;
}
if (interpreter.envPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'use strict';

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

setup(async () => {
shell = mock<IApplicationShell>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,34 @@ suite('Terminal Environment Variable Collection Service', () => {
expect(result).to.equal(true);
});

test('Correct track that prompt was not set for non-Windows where PS1 is not set but env name is base', async () => {
when(platform.osType).thenReturn(OSType.Linux);
const envVars: NodeJS.ProcessEnv = { CONDA_PREFIX: 'prefix/to/conda', ...process.env };
const ps1Shell = 'zsh';
const resource = Uri.file('a');
const workspaceFolder: WorkspaceFolder = {
uri: Uri.file('workspacePath'),
name: 'workspace1',
index: 0,
};
when(interpreterService.getActiveInterpreter(resource)).thenResolve(({
type: PythonEnvType.Conda,
envName: 'base',
envPath: 'prefix/to/conda',
} as unknown) as PythonEnvironment);
when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder);
when(
environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell),
).thenResolve(envVars);
when(collection.replace(anything(), anything(), anything())).thenReturn();

await terminalEnvVarCollectionService._applyCollection(resource, ps1Shell);

const result = terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource);

expect(result).to.equal(false);
});

test('Correct track that prompt was not set for non-Windows fish where PS1 is not set', async () => {
when(platform.osType).thenReturn(OSType.Linux);
const envVars: NodeJS.ProcessEnv = { CONDA_PREFIX: 'prefix/to/conda', ...process.env };
Expand Down

0 comments on commit c1e9b1e

Please sign in to comment.