11import * as fse from 'fs-extra' ;
22import * as path from 'path' ;
33import * as tomljs from '@iarna/toml' ;
4- import { LogOutputChannel , ProgressLocation , QuickInputButtons , Uri } from 'vscode' ;
4+ import { LogOutputChannel , ProgressLocation , QuickInputButtons , QuickPickItem , Uri } from 'vscode' ;
55import { showQuickPickWithButtons , withProgress } from '../../common/window.apis' ;
66import { PackageManagement , Pickers , VenvManagerStrings } from '../../common/localize' ;
77import { PackageManagementOptions , PythonEnvironment , PythonEnvironmentApi , PythonProject } from '../../api' ;
@@ -10,6 +10,7 @@ import { EXTENSION_ROOT_DIR } from '../../common/constants';
1010import { selectFromCommonPackagesToInstall , selectFromInstallableToInstall } from '../common/pickers' ;
1111import { traceInfo } from '../../common/logging' ;
1212import { Installable , mergePackages } from '../common/utils' ;
13+ import { refreshPipPackages } from './utils' ;
1314
1415async function tomlParse ( fsPath : string , log ?: LogOutputChannel ) : Promise < tomljs . JsonMap > {
1516 try {
@@ -83,7 +84,7 @@ async function selectWorkspaceOrCommon(
8384 return undefined ;
8485 }
8586
86- const items = [ ] ;
87+ const items : QuickPickItem [ ] = [ ] ;
8788 if ( installable . length > 0 ) {
8889 items . push ( {
8990 label : PackageManagement . workspaceDependencies ,
@@ -102,27 +103,32 @@ async function selectWorkspaceOrCommon(
102103 items . push ( { label : PackageManagement . skipPackageInstallation } ) ;
103104 }
104105
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+ }
115120
116121 if ( selected && ! Array . isArray ( selected ) ) {
117122 try {
118123 if ( selected . label === PackageManagement . workspaceDependencies ) {
119- const installArgs = await selectFromInstallableToInstall ( installable ) ;
120- return { install : installArgs ?? [ ] , uninstall : [ ] } ;
124+ return await selectFromInstallableToInstall ( installable , undefined , { showBackButton } ) ;
121125 } 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 ) {
124128 traceInfo ( 'Package Installer: user selected skip package installation' ) ;
125129 return undefined ;
130+ } else {
131+ return undefined ;
126132 }
127133 // eslint-disable-next-line @typescript-eslint/no-explicit-any
128134 } catch ( ex : any ) {
@@ -144,12 +150,13 @@ export async function getWorkspacePackagesToInstall(
144150 options : PackageManagementOptions ,
145151 project ?: PythonProject [ ] ,
146152 environment ?: PythonEnvironment ,
153+ log ?: LogOutputChannel ,
147154) : Promise < PipPackages | undefined > {
148155 const installable = ( await getProjectInstallable ( api , project ) ) ?? [ ] ;
149156 let common = await getCommonPackages ( ) ;
150157 let installed : string [ ] | undefined ;
151158 if ( environment ) {
152- installed = ( await api . getPackages ( environment ) ) ?. map ( ( pkg ) => pkg . name ) ;
159+ installed = ( await refreshPipPackages ( environment , log , { showProgress : true } ) ) ?. map ( ( pkg ) => pkg . name ) ;
153160 common = mergePackages ( common , installed ?? [ ] ) ;
154161 }
155162 return selectWorkspaceOrCommon ( installable , common , ! ! options . showSkipOption , installed ?? [ ] ) ;
@@ -166,7 +173,7 @@ export async function getProjectInstallable(
166173 const installable : Installable [ ] = [ ] ;
167174 await withProgress (
168175 {
169- location : ProgressLocation . Window ,
176+ location : ProgressLocation . Notification ,
170177 title : VenvManagerStrings . searchingDependencies ,
171178 } ,
172179 async ( _progress , token ) => {
0 commit comments