Skip to content

Commit 31aa246

Browse files
author
Kartik Raj
authored
Also show env name for prefixed conda envs in terminal prompt (#21899)
1 parent 941fcfa commit 31aa246

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/client/interpreter/activation/terminalEnvVarCollectionPrompt.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { inject, injectable } from 'inversify';
55
import { Uri } from 'vscode';
6+
import * as path from 'path';
67
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types';
78
import {
89
IConfigurationService,
@@ -16,6 +17,7 @@ import { IExtensionSingleActivationService } from '../../activation/types';
1617
import { ITerminalEnvVarCollectionService } from './types';
1718
import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers';
1819
import { IInterpreterService } from '../contracts';
20+
import { PythonEnvironment } from '../../pythonEnvironments/info';
1921

2022
export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY';
2123

@@ -70,7 +72,7 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
7072
}
7173
const prompts = [Common.doNotShowAgain];
7274
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
73-
const terminalPromptName = interpreter?.envName ? ` (${interpreter.envName})` : '';
75+
const terminalPromptName = getPromptName(interpreter);
7476
const selection = await this.appShell.showInformationMessage(
7577
Interpreters.terminalEnvVarCollectionPrompt.format(terminalPromptName),
7678
...prompts,
@@ -83,3 +85,16 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
8385
}
8486
}
8587
}
88+
89+
function getPromptName(interpreter?: PythonEnvironment) {
90+
if (!interpreter) {
91+
return '';
92+
}
93+
if (interpreter.envName) {
94+
return ` "(${interpreter.envName})"`;
95+
}
96+
if (interpreter.envPath) {
97+
return ` "(${path.basename(interpreter.envPath)})"`;
98+
}
99+
return '';
100+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(` "(${envName})"`);
3939

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

0 commit comments

Comments
 (0)