Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 deletions src/client/chat/selectEnvTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { TerminalCodeExecutionProvider } from '../terminals/codeExecution/termin
import {
doesWorkspaceHaveVenvOrCondaEnv,
getEnvDetailsForResponse,
getToolResponseIfNotebook,
IResourceReference,
} from './utils';
import { ITerminalHelper } from '../common/terminal/types';
Expand Down Expand Up @@ -113,39 +112,12 @@ export class SelectPythonEnvTool extends BaseTool<ISelectPythonEnvToolArguments>
}

async prepareInvocationImpl(
options: LanguageModelToolInvocationPrepareOptions<ISelectPythonEnvToolArguments>,
resource: Uri | undefined,
_options: LanguageModelToolInvocationPrepareOptions<ISelectPythonEnvToolArguments>,
_resource: Uri | undefined,
_token: CancellationToken,
): Promise<PreparedToolInvocation> {
if (getToolResponseIfNotebook(resource)) {
return {};
}
const hasVenvOrCondaEnvInWorkspaceFolder = doesWorkspaceHaveVenvOrCondaEnv(resource, this.api);

if (
hasVenvOrCondaEnvInWorkspaceFolder ||
!workspace.workspaceFolders?.length ||
options.input.reason === 'cancelled'
) {
return {
confirmationMessages: {
title: l10n.t('Select a Python Environment?'),
message: '',
},
};
}

return {
confirmationMessages: {
title: l10n.t('Configure a Python Environment?'),
message: l10n.t(
[
'The recommended option is to create a new Python Environment, providing the benefit of isolating packages from other environments. ',
'Optionally you could select an existing Python Environment.',
].join('\n'),
),
},
};
// The environment picker requires an explicit user selection before making any change.
return {};
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/test/chat/selectEnvTool.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { expect } from 'chai';
import { CancellationTokenSource } from 'vscode';
import { SelectPythonEnvTool } from '../../client/chat/selectEnvTool';

suite('Select Python Environment Tool', () => {
test('Does not request confirmation before showing the environment picker', async () => {
const tool = Object.create(SelectPythonEnvTool.prototype) as SelectPythonEnvTool;
const tokenSource = new CancellationTokenSource();

try {
const result = await tool.prepareInvocation(
{ input: { resourcePath: '/workspace' } },
tokenSource.token,
);

expect(result.confirmationMessages).to.be.undefined;
} finally {
tokenSource.dispose();
}
});
});
Loading