Skip to content

Commit

Permalink
Respect VIRTUAL_ENV_PROMPT when calculating PS1 (#23080)
Browse files Browse the repository at this point in the history
Closes #22956

Because we calculate `PS1` ourselves due to a limitation:
#22078, this environment
variable may not end up being respected as do not use `PS1`. This PR
fixes it.
  • Loading branch information
Kartik Raj authored Mar 15, 2024
1 parent cd3ea27 commit 01e5cbd
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 01e5cbd

Please sign in to comment.