1
1
import * as fse from 'fs-extra' ;
2
2
import * as path from 'path' ;
3
3
import * as tomljs from '@iarna/toml' ;
4
- import { LogOutputChannel , ProgressLocation , QuickInputButtons , Uri } from 'vscode' ;
4
+ import { LogOutputChannel , ProgressLocation , QuickInputButtons , QuickPickItem , Uri } from 'vscode' ;
5
5
import { showQuickPickWithButtons , withProgress } from '../../common/window.apis' ;
6
6
import { PackageManagement , Pickers , VenvManagerStrings } from '../../common/localize' ;
7
7
import { PackageManagementOptions , PythonEnvironment , PythonEnvironmentApi , PythonProject } from '../../api' ;
@@ -10,6 +10,7 @@ import { EXTENSION_ROOT_DIR } from '../../common/constants';
10
10
import { selectFromCommonPackagesToInstall , selectFromInstallableToInstall } from '../common/pickers' ;
11
11
import { traceInfo } from '../../common/logging' ;
12
12
import { Installable , mergePackages } from '../common/utils' ;
13
+ import { refreshPipPackages } from './utils' ;
13
14
14
15
async function tomlParse ( fsPath : string , log ?: LogOutputChannel ) : Promise < tomljs . JsonMap > {
15
16
try {
@@ -83,7 +84,7 @@ async function selectWorkspaceOrCommon(
83
84
return undefined ;
84
85
}
85
86
86
- const items = [ ] ;
87
+ const items : QuickPickItem [ ] = [ ] ;
87
88
if ( installable . length > 0 ) {
88
89
items . push ( {
89
90
label : PackageManagement . workspaceDependencies ,
@@ -102,27 +103,32 @@ async function selectWorkspaceOrCommon(
102
103
items . push ( { label : PackageManagement . skipPackageInstallation } ) ;
103
104
}
104
105
105
- const selected =
106
- items . length === 1
107
- ? items [ 0 ]
108
- : await showQuickPickWithButtons ( items , {
109
- placeHolder : Pickers . Packages . selectOption ,
110
- ignoreFocusOut : true ,
111
- showBackButton : true ,
112
- matchOnDescription : false ,
113
- matchOnDetail : false ,
114
- } ) ;
106
+ let showBackButton = true ;
107
+ let selected : QuickPickItem [ ] | QuickPickItem | undefined = undefined ;
108
+ if ( items . length === 1 ) {
109
+ selected = items [ 0 ] ;
110
+ showBackButton = false ;
111
+ } else {
112
+ selected = await showQuickPickWithButtons ( items , {
113
+ placeHolder : Pickers . Packages . selectOption ,
114
+ ignoreFocusOut : true ,
115
+ showBackButton : true ,
116
+ matchOnDescription : false ,
117
+ matchOnDetail : false ,
118
+ } ) ;
119
+ }
115
120
116
121
if ( selected && ! Array . isArray ( selected ) ) {
117
122
try {
118
123
if ( selected . label === PackageManagement . workspaceDependencies ) {
119
- const installArgs = await selectFromInstallableToInstall ( installable ) ;
120
- return { install : installArgs ?? [ ] , uninstall : [ ] } ;
124
+ return await selectFromInstallableToInstall ( installable , undefined , { showBackButton } ) ;
121
125
} else if ( selected . label === PackageManagement . searchCommonPackages ) {
122
- return await selectFromCommonPackagesToInstall ( common , installed ) ;
123
- } else {
126
+ return await selectFromCommonPackagesToInstall ( common , installed , undefined , { showBackButton } ) ;
127
+ } else if ( selected . label === PackageManagement . skipPackageInstallation ) {
124
128
traceInfo ( 'Package Installer: user selected skip package installation' ) ;
125
129
return undefined ;
130
+ } else {
131
+ return undefined ;
126
132
}
127
133
// eslint-disable-next-line @typescript-eslint/no-explicit-any
128
134
} catch ( ex : any ) {
@@ -144,12 +150,13 @@ export async function getWorkspacePackagesToInstall(
144
150
options : PackageManagementOptions ,
145
151
project ?: PythonProject [ ] ,
146
152
environment ?: PythonEnvironment ,
153
+ log ?: LogOutputChannel ,
147
154
) : Promise < PipPackages | undefined > {
148
155
const installable = ( await getProjectInstallable ( api , project ) ) ?? [ ] ;
149
156
let common = await getCommonPackages ( ) ;
150
157
let installed : string [ ] | undefined ;
151
158
if ( environment ) {
152
- installed = ( await api . getPackages ( environment ) ) ?. map ( ( pkg ) => pkg . name ) ;
159
+ installed = ( await refreshPipPackages ( environment , log , { showProgress : true } ) ) ?. map ( ( pkg ) => pkg . name ) ;
153
160
common = mergePackages ( common , installed ?? [ ] ) ;
154
161
}
155
162
return selectWorkspaceOrCommon ( installable , common , ! ! options . showSkipOption , installed ?? [ ] ) ;
@@ -166,7 +173,7 @@ export async function getProjectInstallable(
166
173
const installable : Installable [ ] = [ ] ;
167
174
await withProgress (
168
175
{
169
- location : ProgressLocation . Window ,
176
+ location : ProgressLocation . Notification ,
170
177
title : VenvManagerStrings . searchingDependencies ,
171
178
} ,
172
179
async ( _progress , token ) => {
0 commit comments