@@ -267,6 +267,46 @@ function actionLaunchWrapper(cmds, url) {
267267 return _launchWrapper ;
268268}
269269
270+ // Update the display of the env selector.
271+ function updateEnvSelector ( ) {
272+ statusBarEnv . text =
273+ currentEnv && currentEnv != ENV_DEFAULT
274+ ? `[env:${ currentEnv } ]`
275+ : ENV_DEFAULT ;
276+ statusBarEnv . tooltip = "APIO: Select apio.ini env" ;
277+ }
278+
279+ // Handle that is triggered when the user clicks on the env
280+ // selection field in the status bar.
281+ function envSelectionClickHandler ( context , apioIniPath ) {
282+ // The actual handler.
283+ async function _handler ( ) {
284+ // Scan the apio.ini file and get a list of all of its envs.
285+ const envs = extractApioIniEnvs ( apioIniPath ) ;
286+
287+ // Prepend to the list the (default) menu entry.
288+ envs . unshift ( ENV_DEFAULT ) ;
289+
290+ // Ask the user to select from the list.
291+ let selected = await vscode . window . showQuickPick ( envs , {
292+ placeHolder : "Select apio.ini environment" ,
293+ } ) ;
294+
295+ if ( selected !== undefined ) {
296+ // Update the current env var with the selection.
297+ currentEnv = selected || ENV_DEFAULT ;
298+
299+ // Update the env field in the status bar.
300+ updateEnvSelector ( ) ;
301+
302+ // Persist the default for future invocations vscode and this project.
303+ await context . workspaceState . update ( "apio.activeEnv" , currentEnv ) ;
304+ }
305+ }
306+
307+ return _handler ;
308+ }
309+
270310// Scans apio.ini and return list of env names.
271311function extractApioIniEnvs ( filePath ) {
272312 // const fs = require("fs");
@@ -297,15 +337,6 @@ function extractApioIniEnvs(filePath) {
297337 }
298338}
299339
300- // Update the display of the env selector.
301- function updateEnvSelector ( ) {
302- statusBarEnv . text =
303- currentEnv && currentEnv != ENV_DEFAULT
304- ? `[env:${ currentEnv } ]`
305- : ENV_DEFAULT ;
306- statusBarEnv . tooltip = "APIO: Select apio.ini env" ;
307- }
308-
309340// Standard VSC extension activate() function.
310341function activate ( context ) {
311342 // Init Apio log output channel.
@@ -413,19 +444,10 @@ function activate(context) {
413444
414445 // Register command: click → show QuickPick
415446 context . subscriptions . push (
416- vscode . commands . registerCommand ( "apio.selectEnv" , async ( ) => {
417- const envs = extractApioIniEnvs ( apioIniPath ) ;
418- envs . unshift ( ENV_DEFAULT ) ;
419- const selected = await vscode . window . showQuickPick ( envs , {
420- placeHolder : "Select Apio environment" ,
421- } ) ;
422-
423- if ( selected !== undefined ) {
424- currentEnv = selected || ENV_DEFAULT ;
425- updateEnvSelector ( ) ;
426- await context . workspaceState . update ( "apio.activeEnv" , currentEnv ) ;
427- }
428- } )
447+ vscode . commands . registerCommand (
448+ "apio.selectEnv" ,
449+ envSelectionClickHandler ( context , apioIniPath )
450+ )
429451 ) ;
430452
431453 // All done.
0 commit comments