Skip to content

Commit 5186c96

Browse files
committed
Updates
1 parent 48a0df6 commit 5186c96

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/client/chat/configurePythonEnvTool.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { resolveFilePath } from './utils';
2727
import { ITerminalHelper } from '../common/terminal/types';
2828
import { IRecommendedEnvironmentService } from '../interpreter/configuration/types';
2929
import { CreateVirtualEnvTool } from './createVirtualEnvTool';
30-
import { SelectPythonEnvTool } from './selectEnvTool';
30+
import { ISelectPythonEnvToolArguments, SelectPythonEnvTool } from './selectEnvTool';
3131

3232
export class ConfigurePythonEnvTool implements LanguageModelTool<IResourceReference> {
3333
private readonly terminalExecutionService: TerminalCodeExecutionProvider;
@@ -37,7 +37,7 @@ export class ConfigurePythonEnvTool implements LanguageModelTool<IResourceRefere
3737
constructor(
3838
private readonly api: PythonExtension['environments'],
3939
private readonly serviceContainer: IServiceContainer,
40-
private readonly createVirtualEnvTool: CreateVirtualEnvTool,
40+
private readonly createEnvTool: CreateVirtualEnvTool,
4141
) {
4242
this.terminalExecutionService = this.serviceContainer.get<TerminalCodeExecutionProvider>(
4343
ICodeExecutionService,
@@ -75,22 +75,26 @@ export class ConfigurePythonEnvTool implements LanguageModelTool<IResourceRefere
7575
);
7676
}
7777

78-
let reason: 'cancelled' | undefined;
79-
if (
80-
await this.createVirtualEnvTool.canCreateNewVirtualEnv(resolveFilePath(options.input.resourcePath), token)
81-
) {
82-
reason = 'cancelled';
78+
if (await this.createEnvTool.shouldCreateNewVirtualEnv(resource, token)) {
8379
try {
8480
return await lm.invokeTool(CreateVirtualEnvTool.toolName, options, token);
8581
} catch (ex) {
86-
// If the user cancelled the tool, then we should not invoke the select env tool.
87-
if (!isCancellationError(ex)) {
88-
throw ex;
82+
if (isCancellationError(ex)) {
83+
const input: ISelectPythonEnvToolArguments = {
84+
...options.input,
85+
reason: 'cancelled',
86+
};
87+
// If the user cancelled the tool, then we should invoke the select env tool.
88+
return lm.invokeTool(SelectPythonEnvTool.toolName, { ...options, input }, token);
8989
}
90+
throw ex;
9091
}
92+
} else {
93+
const input: ISelectPythonEnvToolArguments = {
94+
...options.input,
95+
};
96+
return lm.invokeTool(SelectPythonEnvTool.toolName, { ...options, input }, token);
9197
}
92-
93-
return lm.invokeTool(SelectPythonEnvTool.toolName, { ...options, input: { ...options.input, reason } }, token);
9498
}
9599

96100
async prepareInvocation?(

src/client/chat/createVirtualEnvTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class CreateVirtualEnvTool implements LanguageModelTool<IResourceReferenc
135135
}
136136
}
137137

138-
public async canCreateNewVirtualEnv(resource: Uri | undefined, token: CancellationToken): Promise<boolean> {
138+
public async shouldCreateNewVirtualEnv(resource: Uri | undefined, token: CancellationToken): Promise<boolean> {
139139
if (doesWorkspaceHaveVenvOrCondaEnv(resource, this.api)) {
140140
// If we already have a .venv or .conda in this workspace, then do not prompt to create a virtual environment.
141141
return false;

src/client/chat/selectEnvTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { showQuickPick } from '../common/vscodeApis/windowApis';
3838
import { DisposableStore } from '../common/utils/resourceLifecycle';
3939
import { traceError, traceVerbose, traceWarn } from '../logging';
4040

41-
interface ISelectPythonEnvToolArguments extends IResourceReference {
41+
export interface ISelectPythonEnvToolArguments extends IResourceReference {
4242
reason?: 'cancelled';
4343
}
4444

0 commit comments

Comments
 (0)