Skip to content

Commit 89ffbbf

Browse files
authored
fix: for venv common packages shows installed packages pre ticked (#263)
closes #224
1 parent e3dd50e commit 89ffbbf

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/managers/builtin/pipManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class PipPackageManager implements PackageManager, Disposable {
5454

5555
if (selected.length === 0) {
5656
const projects = this.venv.getProjectsByEnvironment(environment);
57-
selected = (await getWorkspacePackagesToInstall(this.api, options, projects)) ?? [];
57+
selected = (await getWorkspacePackagesToInstall(this.api, options, projects, environment)) ?? [];
5858
}
5959

6060
if (selected.length === 0) {

src/managers/builtin/pipUtils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as tomljs from '@iarna/toml';
44
import { LogOutputChannel, ProgressLocation, QuickInputButtons, Uri } from 'vscode';
55
import { showQuickPickWithButtons, withProgress } from '../../common/window.apis';
66
import { PackageManagement, Pickers, VenvManagerStrings } from '../../common/localize';
7-
import { PackageInstallOptions, PythonEnvironmentApi, PythonProject } from '../../api';
7+
import { PackageInstallOptions, PythonEnvironment, PythonEnvironmentApi, PythonProject } from '../../api';
88
import { findFiles } from '../../common/workspace.apis';
99
import { EXTENSION_ROOT_DIR } from '../../common/constants';
1010
import { Installable, selectFromCommonPackagesToInstall, selectFromInstallableToInstall } from '../common/pickers';
@@ -76,6 +76,7 @@ async function selectWorkspaceOrCommon(
7676
installable: Installable[],
7777
common: Installable[],
7878
showSkipOption: boolean,
79+
installed?: string[],
7980
): Promise<string[] | undefined> {
8081
if (installable.length === 0 && common.length === 0) {
8182
return undefined;
@@ -116,7 +117,7 @@ async function selectWorkspaceOrCommon(
116117
if (selected.label === PackageManagement.workspaceDependencies) {
117118
return await selectFromInstallableToInstall(installable);
118119
} else if (selected.label === PackageManagement.commonPackages) {
119-
return await selectFromCommonPackagesToInstall(common);
120+
return await selectFromCommonPackagesToInstall(common, installed);
120121
} else {
121122
traceInfo('Package Installer: user selected skip package installation');
122123
return undefined;
@@ -135,10 +136,15 @@ export async function getWorkspacePackagesToInstall(
135136
api: PythonEnvironmentApi,
136137
options?: PackageInstallOptions,
137138
project?: PythonProject[],
139+
environment?: PythonEnvironment,
138140
): Promise<string[] | undefined> {
139141
const installable = (await getProjectInstallable(api, project)) ?? [];
140142
const common = await getCommonPackages();
141-
return selectWorkspaceOrCommon(installable, common, !!options?.showSkipOption);
143+
let installed: string[] | undefined;
144+
if (environment) {
145+
installed = (await api.getPackages(environment))?.map((pkg) => pkg.name);
146+
}
147+
return selectWorkspaceOrCommon(installable, common, !!options?.showSkipOption, installed);
142148
}
143149

144150
export async function getProjectInstallable(

src/managers/common/pickers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,13 @@ async function enterPackageManually(filler?: string): Promise<string[] | undefin
119119

120120
export async function selectFromCommonPackagesToInstall(
121121
common: Installable[],
122+
installed?: string[],
122123
preSelected?: PackageQuickPickItem[] | undefined,
123124
): Promise<string[] | undefined> {
124125
const items: PackageQuickPickItem[] = common.map(installableToQuickPickItem);
125126
const preSelectedItems = items
126127
.filter((i) => i.kind !== QuickPickItemKind.Separator)
127-
.filter((i) =>
128-
preSelected?.find((s) => s.label === i.label && s.description === i.description && s.detail === i.detail),
129-
);
128+
.filter((i) => installed?.find((p) => i.id === p) || preSelected?.find((s) => s.id === i.id));
130129

131130
let selected: PackageQuickPickItem | PackageQuickPickItem[] | undefined;
132131
try {
@@ -173,7 +172,7 @@ export async function selectFromCommonPackagesToInstall(
173172
return result;
174173
} catch (ex) {
175174
if (ex === QuickInputButtons.Back) {
176-
return selectFromCommonPackagesToInstall(common, selected);
175+
return selectFromCommonPackagesToInstall(common, installed, selected);
177176
}
178177
return undefined;
179178
}

0 commit comments

Comments
 (0)