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

Respect VIRTUAL_ENV_PROMPT when calculating PS1 #23080

Merged
merged 2 commits into from
Mar 15, 2024
Merged
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
9 changes: 7 additions & 2 deletions src/client/terminals/envCollectionActivation/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
}

private async getPS1(shell: string, resource: Resource, env: EnvironmentVariables) {
// PS1 returned by shell is not predictable: #22078
// Hence calculate it ourselves where possible. Should no longer be needed once #22128 is available.
const customShellType = identifyShellFromShellPath(shell);
if (this.noPromptVariableShells.includes(customShellType)) {
return env.PS1;
Expand All @@ -347,7 +349,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const shouldSetPS1 = shouldPS1BeSet(interpreter?.type, env);
if (shouldSetPS1) {
const prompt = getPromptForEnv(interpreter);
const prompt = getPromptForEnv(interpreter, env);
if (prompt) {
return prompt;
}
Expand Down Expand Up @@ -456,7 +458,7 @@ function shouldSkip(env: string) {
].includes(env);
}

function getPromptForEnv(interpreter: PythonEnvironment | undefined) {
function getPromptForEnv(interpreter: PythonEnvironment | undefined, env: EnvironmentVariables) {
if (!interpreter) {
return undefined;
}
Expand All @@ -465,6 +467,9 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) {
// If conda base environment is selected, it can lead to "(base)" appearing twice if we return the env name.
return undefined;
}
if (interpreter.type === PythonEnvType.Virtual && env.VIRTUAL_ENV_PROMPT) {
return `(${env.VIRTUAL_ENV_PROMPT}) `;
}
return `(${interpreter.envName}) `;
}
if (interpreter.envPath) {
Expand Down
Loading