Skip to content

Commit 8eacbe7

Browse files
committed
fix: shell type API
1 parent e140b96 commit 8eacbe7

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { AutoFindProjects } from './features/creators/autoFindProjects';
5656
import { registerTools } from './common/lm.apis';
5757
import { GetPackagesTool } from './features/copilotTools';
5858
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
59-
import { getEnvironmentForTerminal } from './features/terminal/utils';
59+
import { getEnvironmentForTerminal, normalizeShellPath } from './features/terminal/utils';
6060
import { PowershellStartupProvider } from './features/terminal/startup/powershellStartup';
6161
import { ShellStartupActivationManagerImpl } from './features/terminal/startup/activateUsingShellStartup';
6262
import { BashStartupProvider, GitBashStartupProvider } from './features/terminal/startup/bashStartup';
@@ -251,7 +251,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
251251
const envVar = shellEnv.value;
252252
if (envVar) {
253253
if (envVar['VIRTUAL_ENV']) {
254-
const env = await api.resolveEnvironment(Uri.file(envVar['VIRTUAL_ENV']));
254+
const envPath = normalizeShellPath(envVar['VIRTUAL_ENV'], e.terminal.state.shell);
255+
const env = await api.resolveEnvironment(Uri.file(envPath));
255256
if (env) {
256257
monitoredTerminals.set(e.terminal, env);
257258
terminalActivation.updateActivationState(e.terminal, env, true);

src/features/terminal/startup/bashStartup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ async function getZshProfiles(): Promise<string[]> {
5252
return result.map((p) => p.profilePath);
5353
}
5454

55-
const regionStart = '# vscode python environment activation begin';
56-
const regionEnd = '# vscode python environment activation end';
55+
const regionStart = '# >>> vscode python';
56+
const regionEnd = '# <<< vscode python';
5757

5858
function getActivationContent(): string {
5959
const lineSep = '\n';

src/features/terminal/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Terminal, TerminalOptions, Uri } from 'vscode';
33
import { sleep } from '../../common/utils/asyncUtils';
44
import { PythonEnvironment, PythonProject, PythonProjectEnvironmentApi, PythonProjectGetterApi } from '../../api';
55
import { getConfiguration, getWorkspaceFolders } from '../../common/workspace.apis';
6+
import { isWindows } from '../../common/utils/platformUtils';
67

78
const SHELL_INTEGRATION_TIMEOUT = 500; // 0.5 seconds
89
const SHELL_INTEGRATION_POLL_INTERVAL = 20; // 0.02 seconds
@@ -125,3 +126,12 @@ export async function getAllDistinctProjectEnvironments(
125126

126127
return envs.length > 0 ? envs : undefined;
127128
}
129+
130+
export function normalizeShellPath(filePath: string, shellType?: string): string {
131+
if (isWindows() && shellType) {
132+
if (shellType.toLowerCase() === 'gitbash' || shellType.toLowerCase() === 'git-bash') {
133+
return filePath.replace(/\\/g, '/').replace(/^\/([a-zA-Z])/, '$1:');
134+
}
135+
}
136+
return filePath;
137+
}

0 commit comments

Comments
 (0)