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

Also show env name for prefixed conda envs in terminal prompt #21899

Merged
merged 3 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 @@ -3,6 +3,7 @@

import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import * as path from 'path';
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types';
import {
IConfigurationService,
Expand All @@ -16,6 +17,7 @@ import { IExtensionSingleActivationService } from '../../activation/types';
import { ITerminalEnvVarCollectionService } from './types';
import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers';
import { IInterpreterService } from '../contracts';
import { PythonEnvironment } from '../../pythonEnvironments/info';

export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY';

Expand Down Expand Up @@ -70,7 +72,7 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
}
const prompts = [Common.doNotShowAgain];
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const terminalPromptName = interpreter?.envName ? ` (${interpreter.envName})` : '';
const terminalPromptName = getPromptName(interpreter);
const selection = await this.appShell.showInformationMessage(
Interpreters.terminalEnvVarCollectionPrompt.format(terminalPromptName),
...prompts,
Expand All @@ -83,3 +85,16 @@ export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivatio
}
}
}

function getPromptName(interpreter?: PythonEnvironment) {
if (!interpreter) {
return '';
}
if (interpreter.envName) {
return ` "(${interpreter.envName})"`;
}
if (interpreter.envPath) {
return ` "(${path.basename(interpreter.envPath)})"`;
}
return '';
}
Original file line number Diff line number Diff line change
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(` "(${envName})"`);

setup(async () => {
shell = mock<IApplicationShell>();
Expand Down