Skip to content

Commit cc4cafc

Browse files
committed
fix: wrong env used when installing package
1 parent 900ae9c commit cc4cafc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/client/chat/createVirtualEnvTool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export class CreateVirtualEnvTool extends BaseTool<ICreateVirtualEnvToolParams>
104104
createVirtualEnvironment({
105105
interpreter: preferredGlobalPythonEnv.id,
106106
workspaceFolder,
107+
selectEnvironment: true,
107108
}),
108109
token,
109110
);

src/client/chat/installPackagesTool.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
LanguageModelToolResult,
1212
PreparedToolInvocation,
1313
Uri,
14+
workspace,
1415
} from 'vscode';
1516
import { PythonExtension } from '../api/types';
1617
import { IServiceContainer } from '../ioc/types';
@@ -58,7 +59,14 @@ export class InstallPackagesTool extends BaseTool<IInstallPackageArgs>
5859

5960
if (useEnvExtension()) {
6061
const api = await getEnvExtApi();
61-
const env = await api.getEnvironment(resourcePath);
62+
// Normalize resourcePath to workspace folder for environment lookup.
63+
// This ensures consistency with CreateVirtualEnvTool which creates environments
64+
// for workspace folders, not individual files.
65+
const workspaceFolder = resourcePath
66+
? workspace.getWorkspaceFolder(resourcePath)
67+
: workspace.workspaceFolders?.[0];
68+
const envScope = workspaceFolder?.uri ?? resourcePath;
69+
const env = await api.getEnvironment(envScope);
6270
if (env) {
6371
await raceCancellationError(api.managePackages(env, { install: options.input.packageList }), token);
6472
const resultMessage = `Successfully installed ${packagePlurality}: ${options.input.packageList.join(

0 commit comments

Comments
 (0)