Skip to content

Commit cd1b06e

Browse files
committed
Show requirement files
1 parent 9ebc5eb commit cd1b06e

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/client/common/utils/localize.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ export namespace CreateEnv {
475475
);
476476
export const deletingEnvironmentProgress = l10n.t('Deleting existing ".venv" environment...');
477477
export const errorDeletingEnvironment = l10n.t('Error while deleting existing ".venv" environment.');
478+
export const openRequirementsFile = l10n.t('Open requirements file');
478479
}
479480

480481
export namespace Conda {

src/client/common/vscodeApis/windowApis.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ import {
1616
TextEditor,
1717
window,
1818
Disposable,
19+
QuickPickItemButtonEvent,
20+
Uri,
1921
} from 'vscode';
2022
import { createDeferred, Deferred } from '../utils/async';
2123

24+
export function showTextDocument(uri: Uri): Thenable<TextEditor> {
25+
return window.showTextDocument(uri);
26+
}
27+
2228
export function showQuickPick<T extends QuickPickItem>(
2329
items: readonly T[] | Thenable<readonly T[]>,
2430
options?: QuickPickOptions,
@@ -91,6 +97,7 @@ export async function showQuickPickWithBack<T extends QuickPickItem>(
9197
items: readonly T[],
9298
options?: QuickPickOptions,
9399
token?: CancellationToken,
100+
itemButtonHandler?: (e: QuickPickItemButtonEvent<T>) => void,
94101
): Promise<T | T[] | undefined> {
95102
const quickPick: QuickPick<T> = window.createQuickPick<T>();
96103
const disposables: Disposable[] = [quickPick];
@@ -130,6 +137,11 @@ export async function showQuickPickWithBack<T extends QuickPickItem>(
130137
deferred.resolve(undefined);
131138
}
132139
}),
140+
quickPick.onDidTriggerItemButton((e) => {
141+
if (itemButtonHandler) {
142+
itemButtonHandler(e);
143+
}
144+
}),
133145
);
134146
if (token) {
135147
disposables.push(

src/client/pythonEnvironments/creation/provider/venvUtils.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import * as tomljs from '@iarna/toml';
55
import * as fs from 'fs-extra';
66
import { flatten, isArray } from 'lodash';
77
import * as path from 'path';
8-
import { CancellationToken, ProgressLocation, QuickPickItem, RelativePattern, WorkspaceFolder } from 'vscode';
8+
import {
9+
CancellationToken,
10+
ProgressLocation,
11+
QuickPickItem,
12+
QuickPickItemButtonEvent,
13+
RelativePattern,
14+
ThemeIcon,
15+
Uri,
16+
WorkspaceFolder,
17+
} from 'vscode';
918
import { Common, CreateEnv } from '../../../common/utils/localize';
1019
import {
1120
MultiStepAction,
1221
MultiStepNode,
1322
showQuickPickWithBack,
23+
showTextDocument,
1424
withProgress,
1525
} from '../../../common/vscodeApis/windowApis';
1626
import { findFiles } from '../../../common/vscodeApis/workspaceApis';
@@ -78,8 +88,13 @@ async function pickTomlExtras(extras: string[], token?: CancellationToken): Prom
7888
return undefined;
7989
}
8090

81-
async function pickRequirementsFiles(files: string[], token?: CancellationToken): Promise<string[] | undefined> {
91+
async function pickRequirementsFiles(
92+
files: string[],
93+
root: string,
94+
token?: CancellationToken,
95+
): Promise<string[] | undefined> {
8296
const items: QuickPickItem[] = files
97+
.map((p) => path.relative(root, p))
8398
.sort((a, b) => {
8499
const al: number = a.split(/[\\\/]/).length;
85100
const bl: number = b.split(/[\\\/]/).length;
@@ -91,7 +106,15 @@ async function pickRequirementsFiles(files: string[], token?: CancellationToken)
91106
}
92107
return al - bl;
93108
})
94-
.map((e) => ({ label: e }));
109+
.map((e) => ({
110+
label: e,
111+
buttons: [
112+
{
113+
iconPath: new ThemeIcon('go-to-file'),
114+
tooltip: CreateEnv.Venv.openRequirementsFile,
115+
},
116+
],
117+
}));
95118

96119
const selection = await showQuickPickWithBack(
97120
items,
@@ -101,6 +124,11 @@ async function pickRequirementsFiles(files: string[], token?: CancellationToken)
101124
canPickMany: true,
102125
},
103126
token,
127+
async (e: QuickPickItemButtonEvent<QuickPickItem>) => {
128+
if (e.item.label) {
129+
await showTextDocument(Uri.file(path.join(root, e.item.label)));
130+
}
131+
},
104132
);
105133

106134
if (selection && isArray(selection)) {
@@ -195,14 +223,11 @@ export async function pickPackagesToInstall(
195223
tomlStep,
196224
async (context?: MultiStepAction) => {
197225
traceVerbose('Looking for pip requirements.');
198-
const requirementFiles = (await getPipRequirementsFiles(workspaceFolder, token))?.map((p) =>
199-
path.relative(workspaceFolder.uri.fsPath, p),
200-
);
201-
226+
const requirementFiles = await getPipRequirementsFiles(workspaceFolder, token);
202227
if (requirementFiles && requirementFiles.length > 0) {
203228
traceVerbose('Found pip requirements.');
204229
try {
205-
const result = await pickRequirementsFiles(requirementFiles, token);
230+
const result = await pickRequirementsFiles(requirementFiles, workspaceFolder.uri.fsPath, token);
206231
const installList = result?.map((p) => path.join(workspaceFolder.uri.fsPath, p));
207232
if (installList) {
208233
installList.forEach((i) => {

0 commit comments

Comments
 (0)