Skip to content

Commit

Permalink
Also show env name for prefixed conda envs in terminal prompt (#21899)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored Aug 30, 2023
1 parent 941fcfa commit 31aa246
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 31aa246

Please sign in to comment.