@@ -23,37 +23,44 @@ export class EnvironmentController {
2323
2424 private environmentStatusEntry : EnvironmentStatusEntry ;
2525
26- public constructor ( initEnvironment : EnvironmentPickItem ) {
26+ private currentEnvironment : EnvironmentPickItem ;
27+
28+ private constructor ( initEnvironment : EnvironmentPickItem ) {
29+ this . currentEnvironment = initEnvironment ;
2730 this . environmentStatusEntry = new EnvironmentStatusEntry ( initEnvironment . label ) ;
2831 }
2932
3033 @trace ( 'Switch Environment' )
3134 public async switchEnvironment ( ) {
32- const currentEnvironment = await EnvironmentController . getCurrentEnvironment ( ) ;
33- const itemPickList : EnvironmentPickItem [ ] = [ ] ;
34- itemPickList . push ( EnvironmentController . noEnvironmentPickItem ) ;
35- for ( const name in this . settings . environmentVariables ) {
36- if ( name === EnvironmentController . sharedEnvironmentName ) {
37- continue ;
38- }
39- const item : EnvironmentPickItem = { name, label : name } ;
40- if ( item . name === currentEnvironment . name ) {
41- item . description = '$(check)' ;
42- }
43- itemPickList . push ( item ) ;
44- }
35+ // Add no environment at the top
36+ const userEnvironments : EnvironmentPickItem [ ] =
37+ Object . keys ( this . settings . environmentVariables )
38+ . filter ( name => name !== EnvironmentController . sharedEnvironmentName )
39+ . map ( name => ( {
40+ name,
41+ label : name ,
42+ description : name === this . currentEnvironment . name ? '$(check)' : undefined
43+ } ) ) ;
4544
45+ const itemPickList : EnvironmentPickItem [ ] = [ EnvironmentController . noEnvironmentPickItem , ...userEnvironments ] ;
4646 const item = await window . showQuickPick ( itemPickList , { placeHolder : "Select REST Client Environment" } ) ;
4747 if ( ! item ) {
4848 return ;
4949 }
5050
51+ this . currentEnvironment = item ;
52+
5153 EnvironmentController . _onDidChangeEnvironment . fire ( item . label ) ;
5254 this . environmentStatusEntry . update ( item . label ) ;
5355
5456 await PersistUtility . saveEnvironment ( item ) ;
5557 }
5658
59+ public static async create ( ) : Promise < EnvironmentController > {
60+ const environment = await this . getCurrentEnvironment ( ) ;
61+ return new EnvironmentController ( environment ) ;
62+ }
63+
5764 public static async getCurrentEnvironment ( ) : Promise < EnvironmentPickItem > {
5865 let currentEnvironment = await PersistUtility . loadEnvironment ( ) ;
5966 if ( ! currentEnvironment ) {
0 commit comments