Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply feedback for terminal activation prompt #21905

Merged
merged 2 commits into from
Aug 30, 2023
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
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
Loading