Skip to content

Commit 2ee1e03

Browse files
committed
Updates
1 parent 0b08580 commit 2ee1e03

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,8 @@
15071507
"type": "string"
15081508
}
15091509
},
1510-
"description": "The path to the Python file or workspace to get the environment information for.",
1511-
"required": [
1512-
"resourcePath"
1513-
]
1510+
"description": "The path to the Python file or workspace to get the executable information for. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace.",
1511+
"required": []
15141512
},
15151513
"when": "!pythonEnvExtensionInstalled"
15161514
},
@@ -1532,10 +1530,8 @@
15321530
"type": "string"
15331531
}
15341532
},
1535-
"description": "The path to the Python file or workspace to get the environment information for.",
1536-
"required": [
1537-
"resourcePath"
1538-
]
1533+
"description": "The path to the Python file or workspace to list the packages. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace.",
1534+
"required": []
15391535
},
15401536
"when": "!pythonEnvExtensionInstalled"
15411537
},
@@ -1562,12 +1558,11 @@
15621558
},
15631559
"resourcePath": {
15641560
"type": "string",
1565-
"description": "The path to the Python file or workspace to get the environment information for."
1561+
"description": "The path to the Python file or workspace into which the packages are installed. If not provided, the current workspace will be used. Where possible pass the path to the file or workspace."
15661562
}
15671563
},
15681564
"required": [
1569-
"packageList",
1570-
"resourcePath"
1565+
"packageList"
15711566
]
15721567
},
15731568
"when": "!pythonEnvExtensionInstalled"

src/client/chat/getExecutableTool.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
2525
import { Conda } from '../pythonEnvironments/common/environmentManagers/conda';
2626

2727
export interface IResourceReference {
28-
resourcePath: string;
28+
resourcePath?: string;
2929
}
3030

3131
export class GetExecutableTool implements LanguageModelTool<IResourceReference> {
@@ -54,7 +54,7 @@ export class GetExecutableTool implements LanguageModelTool<IResourceReference>
5454
const envPath = this.api.getActiveEnvironmentPath(resourcePath);
5555
const environment = await raceCancellationError(this.api.resolveEnvironment(envPath), token);
5656
if (!environment || !environment.version) {
57-
throw new Error('No environment found for the provided resource path: ' + resourcePath.fsPath);
57+
throw new Error('No environment found for the provided resource path: ' + resourcePath?.fsPath);
5858
}
5959
const runCommand = await raceCancellationError(this.getTerminalCommand(environment, resourcePath), token);
6060

@@ -78,7 +78,7 @@ export class GetExecutableTool implements LanguageModelTool<IResourceReference>
7878
}
7979
}
8080

81-
private async getTerminalCommand(environment: ResolvedEnvironment, resource: Uri) {
81+
private async getTerminalCommand(environment: ResolvedEnvironment, resource?: Uri) {
8282
let cmd: { command: string; args: string[] };
8383
if (isCondaEnv(environment)) {
8484
cmd =

src/client/chat/getPythonEnvTool.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { Conda } from '../pythonEnvironments/common/environmentManagers/conda';
2525
import { traceError } from '../logging';
2626

2727
export interface IResourceReference {
28-
resourcePath: string;
28+
resourcePath?: string;
2929
}
3030

3131
interface EnvironmentInfo {
@@ -79,7 +79,7 @@ export class GetEnvironmentInfoTool implements LanguageModelTool<IResourceRefere
7979
const envPath = this.api.getActiveEnvironmentPath(resourcePath);
8080
const environment = await raceCancellationError(this.api.resolveEnvironment(envPath), token);
8181
if (!environment || !environment.version) {
82-
throw new Error('No environment found for the provided resource path: ' + resourcePath.fsPath);
82+
throw new Error('No environment found for the provided resource path: ' + resourcePath?.fsPath);
8383
}
8484
const cmd = await raceCancellationError(
8585
this.terminalExecutionService.getExecutableInfo(resourcePath),
@@ -149,7 +149,7 @@ function BuildEnvironmentInfoContent(envInfo: EnvironmentInfo): LanguageModelTex
149149
return new LanguageModelTextPart(content);
150150
}
151151

152-
async function listPipPackages(execFactory: IPythonExecutionFactory, resource: Uri) {
152+
async function listPipPackages(execFactory: IPythonExecutionFactory, resource: Uri | undefined) {
153153
// Add option --format to subcommand list of pip cache, with abspath choice to output the full path of a wheel file. (#8355)
154154
// Added in 202. Thats almost 5 years ago. When Python 3.8 was released.
155155
const exec = await execFactory.createActivatedEnvironment({ allowEnvironmentFetchExceptions: true, resource });
@@ -160,7 +160,7 @@ async function listPipPackages(execFactory: IPythonExecutionFactory, resource: U
160160
async function listCondaPackages(
161161
execFactory: IPythonExecutionFactory,
162162
env: ResolvedEnvironment,
163-
resource: Uri,
163+
resource: Uri | undefined,
164164
processService: IProcessService,
165165
) {
166166
const conda = await Conda.getConda();

src/client/chat/installPackagesTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ModuleInstallerType } from '../pythonEnvironments/info';
2121
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
2222

2323
export interface IInstallPackageArgs {
24-
resourcePath: string;
24+
resourcePath?: string;
2525
packageList: string[];
2626
}
2727

@@ -51,7 +51,7 @@ export class InstallPackagesTool implements LanguageModelTool<IInstallPackageArg
5151
const envPath = this.api.getActiveEnvironmentPath(resourcePath);
5252
const environment = await raceCancellationError(this.api.resolveEnvironment(envPath), token);
5353
if (!environment || !environment.version) {
54-
throw new Error('No environment found for the provided resource path: ' + resourcePath.fsPath);
54+
throw new Error('No environment found for the provided resource path: ' + resourcePath?.fsPath);
5555
}
5656
const isConda = (environment.environment?.type || '').toLowerCase() === 'conda';
5757
const installers = this.serviceContainer.getAll<IModuleInstaller>(IModuleInstaller);

src/client/chat/listPackagesTool.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { traceError } from '../logging';
2424
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
2525

2626
export interface IResourceReference {
27-
resourcePath: string;
27+
resourcePath?: string;
2828
}
2929

3030
export class ListPythonPackagesTool implements LanguageModelTool<IResourceReference> {
@@ -51,7 +51,7 @@ export class ListPythonPackagesTool implements LanguageModelTool<IResourceRefere
5151
const envPath = this.api.getActiveEnvironmentPath(resourcePath);
5252
const environment = await raceCancellationError(this.api.resolveEnvironment(envPath), token);
5353
if (!environment) {
54-
throw new Error('No environment found for the provided resource path: ' + resourcePath.fsPath);
54+
throw new Error('No environment found for the provided resource path: ' + resourcePath?.fsPath);
5555
}
5656

5757
const packages = isCondaEnv(environment)
@@ -102,7 +102,7 @@ export class ListPythonPackagesTool implements LanguageModelTool<IResourceRefere
102102
}
103103

104104

105-
async function listPipPackages(execFactory: IPythonExecutionFactory, resource: Uri): Promise<[packageName:string, version:string][]> {
105+
async function listPipPackages(execFactory: IPythonExecutionFactory, resource: Uri | undefined): Promise<[packageName:string, version:string][]> {
106106
// Add option --format to subcommand list of pip cache, with abspath choice to output the full path of a wheel file. (#8355)
107107
// Added in 202. Thats almost 5 years ago. When Python 3.8 was released.
108108
const exec = await execFactory.createActivatedEnvironment({ allowEnvironmentFetchExceptions: true, resource });
@@ -113,7 +113,7 @@ async function listPipPackages(execFactory: IPythonExecutionFactory, resource: U
113113
async function listCondaPackages(
114114
execFactory: IPythonExecutionFactory,
115115
env: ResolvedEnvironment,
116-
resource: Uri,
116+
resource: Uri | undefined,
117117
processService: IProcessService,
118118
): Promise<[packageName:string, version:string][]> {
119119
const conda = await Conda.getConda();

src/client/chat/utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { CancellationError, CancellationToken, Uri } from 'vscode';
4+
import { CancellationError, CancellationToken, Uri, workspace } from 'vscode';
55
import { IDiscoveryAPI } from '../pythonEnvironments/base/locator';
66
import { PythonExtension, ResolvedEnvironment } from '../api/types';
77

8-
export function resolveFilePath(filepath: string): Uri {
8+
export function resolveFilePath(filepath?: string): Uri | undefined {
9+
if (!filepath) {
10+
return workspace.workspaceFolders ? workspace.workspaceFolders[0].uri : undefined;
11+
}
912
// starts with a scheme
1013
try {
1114
return Uri.parse(filepath);
@@ -28,7 +31,7 @@ export function raceCancellationError<T>(promise: Promise<T>, token: Cancellatio
2831
});
2932
}
3033

31-
export async function getEnvDisplayName(discovery: IDiscoveryAPI, resource: Uri, api: PythonExtension['environments']) {
34+
export async function getEnvDisplayName(discovery: IDiscoveryAPI, resource: Uri | undefined, api: PythonExtension['environments']) {
3235
try {
3336
const envPath = api.getActiveEnvironmentPath(resource);
3437
const env = await discovery.resolveEnv(envPath.path);

0 commit comments

Comments
 (0)