diff --git a/package.json b/package.json index a368ba51..9dc7176b 100644 --- a/package.json +++ b/package.json @@ -520,6 +520,7 @@ "chatParticipantPrivate", "chatParticipantAdditions", "chatVariableResolver", + "terminalShellEnv", "terminalShellType" ] } diff --git a/src/features/terminal/terminalManager.ts b/src/features/terminal/terminalManager.ts index f68ca198..6ae69405 100644 --- a/src/features/terminal/terminalManager.ts +++ b/src/features/terminal/terminalManager.ts @@ -375,6 +375,11 @@ export class TerminalManagerImpl implements TerminalManager { } public isActivated(terminal: Terminal, environment?: PythonEnvironment): boolean { + const envVar = terminal.shellIntegration?.env; + if (envVar) { + return !!envVar['VIRTUAL_ENV']; + } + if (!environment) { return this.activatedTerminals.has(terminal); } diff --git a/src/vscode.proposed.terminalShellEnv.d.ts b/src/vscode.proposed.terminalShellEnv.d.ts new file mode 100644 index 00000000..ffe0b76e --- /dev/null +++ b/src/vscode.proposed.terminalShellEnv.d.ts @@ -0,0 +1,18 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +declare module 'vscode' { + // @anthonykim1 @tyriar https://github.com/microsoft/vscode/issues/227467 + + export interface TerminalShellIntegration { + /** + * The environment of the shell process. This is undefined if the shell integration script + * does not send the environment. + */ + readonly env: { [key: string]: string | undefined } | undefined; + } + + // TODO: Is it fine that this shares onDidChangeTerminalShellIntegration with cwd and the shellIntegration object itself? +}