Skip to content

Commit 205adbd

Browse files
authored
Use Terminal Shell Env API to detect activations (#155)
This was a very easy API to consume.
1 parent c054e7a commit 205adbd

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@
520520
"chatParticipantPrivate",
521521
"chatParticipantAdditions",
522522
"chatVariableResolver",
523+
"terminalShellEnv",
523524
"terminalShellType"
524525
]
525526
}

src/features/terminal/terminalManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ export class TerminalManagerImpl implements TerminalManager {
375375
}
376376

377377
public isActivated(terminal: Terminal, environment?: PythonEnvironment): boolean {
378+
const envVar = terminal.shellIntegration?.env;
379+
if (envVar) {
380+
return !!envVar['VIRTUAL_ENV'];
381+
}
382+
378383
if (!environment) {
379384
return this.activatedTerminals.has(terminal);
380385
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'vscode' {
7+
// @anthonykim1 @tyriar https://github.com/microsoft/vscode/issues/227467
8+
9+
export interface TerminalShellIntegration {
10+
/**
11+
* The environment of the shell process. This is undefined if the shell integration script
12+
* does not send the environment.
13+
*/
14+
readonly env: { [key: string]: string | undefined } | undefined;
15+
}
16+
17+
// TODO: Is it fine that this shares onDidChangeTerminalShellIntegration with cwd and the shellIntegration object itself?
18+
}

0 commit comments

Comments
 (0)