@@ -25,6 +25,7 @@ import { getManifest } from './util/extensionManagmentUtill';
25
25
import { GitpodWorkspacePort , PortInfo , iconStatusMap } from './util/port' ;
26
26
import { ReleaseNotes } from './releaseNotes' ;
27
27
import { registerWelcomeWalkthroughContribution , WELCOME_WALKTROUGH_KEY } from './welcomeWalktrough' ;
28
+ import { ExperimentalSettings , isUserOverrideSetting } from './experiments' ;
28
29
29
30
let gitpodContext : GitpodExtensionContext | undefined ;
30
31
export async function activate ( context : vscode . ExtensionContext ) {
@@ -516,8 +517,16 @@ function getNonce() {
516
517
517
518
interface PortItem { port : GitpodWorkspacePort ; isWebview ?: boolean }
518
519
519
- function registerPorts ( context : GitpodExtensionContext ) : void {
520
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
520
+ async function registerPorts ( context : GitpodExtensionContext ) : Promise < void > {
521
+
522
+ const packageJSON = context . extension . packageJSON ;
523
+ const experiments = new ExperimentalSettings ( 'gitpod' , packageJSON . version , context . logger , context . info . getGitpodHost ( ) ) ;
524
+ context . subscriptions . push ( experiments ) ;
525
+ async function getPortsViewExperimentEnable ( ) : Promise < boolean > {
526
+ return ( await experiments . get < boolean > ( 'gitpod.experimental.portsView.enabled' , ( await context . user ) . id , { team_ids : ( await context . userTeams ) . map ( e => e . id ) . join ( ',' ) , } ) ) ! ;
527
+ }
528
+
529
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
521
530
522
531
const portMap = new Map < number , GitpodWorkspacePort > ( ) ;
523
532
const tunnelMap = new Map < number , vscode . TunnelDescription > ( ) ;
@@ -577,6 +586,7 @@ function registerPorts(context: GitpodExtensionContext): void {
577
586
}
578
587
} ) ;
579
588
}
589
+
580
590
context . subscriptions . push ( observePortsStatus ( ) ) ;
581
591
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.resolveExternalPort' , ( portNumber : number ) => {
582
592
// eslint-disable-next-line no-async-promise-executor
@@ -616,14 +626,14 @@ function registerPorts(context: GitpodExtensionContext): void {
616
626
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePrivate' , ( { port, isWebview } : PortItem ) => {
617
627
context . fireAnalyticsEvent ( {
618
628
eventName : 'vscode_execute_command_gitpod_ports' ,
619
- properties : { action : 'private' , isWebview : ! ! isWebview }
629
+ properties : { action : 'private' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
620
630
} ) ;
621
631
return port . setPortVisibility ( 'private' ) ;
622
632
} ) ) ;
623
633
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePublic' , ( { port, isWebview } : PortItem ) => {
624
634
context . fireAnalyticsEvent ( {
625
635
eventName : 'vscode_execute_command_gitpod_ports' ,
626
- properties : { action : 'public' , isWebview : ! ! isWebview }
636
+ properties : { action : 'public' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
627
637
} ) ;
628
638
return port . setPortVisibility ( 'public' ) ;
629
639
} ) ) ;
@@ -636,14 +646,14 @@ function registerPorts(context: GitpodExtensionContext): void {
636
646
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.preview' , ( { port, isWebview } : PortItem ) => {
637
647
context . fireAnalyticsEvent ( {
638
648
eventName : 'vscode_execute_command_gitpod_ports' ,
639
- properties : { action : 'preview' , isWebview : ! ! isWebview }
649
+ properties : { action : 'preview' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
640
650
} ) ;
641
651
return openPreview ( port ) ;
642
652
} ) ) ;
643
653
context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.openBrowser' , ( { port, isWebview } : PortItem ) => {
644
654
context . fireAnalyticsEvent ( {
645
655
eventName : 'vscode_execute_command_gitpod_ports' ,
646
- properties : { action : 'openBrowser' , isWebview : ! ! isWebview }
656
+ properties : { action : 'openBrowser' , isWebview : ! ! isWebview , userOverride : String ( isUserOverrideSetting ( 'gitpod.experimental.portsView.enabled' ) ) }
647
657
} ) ;
648
658
return openExternal ( port ) ;
649
659
} ) ) ;
@@ -657,7 +667,7 @@ function registerPorts(context: GitpodExtensionContext): void {
657
667
658
668
const portsStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ;
659
669
context . subscriptions . push ( portsStatusBarItem ) ;
660
- function updateStatusBar ( ) : void {
670
+ async function updateStatusBar ( ) : Promise < void > {
661
671
const exposedPorts : number [ ] = [ ] ;
662
672
663
673
for ( const port of portMap . values ( ) ) {
@@ -679,8 +689,8 @@ function registerPorts(context: GitpodExtensionContext): void {
679
689
680
690
portsStatusBarItem . text = text ;
681
691
portsStatusBarItem . tooltip = tooltip ;
682
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
683
- portsStatusBarItem . command = isPortsViewExperimentEnable ? 'gitpod.portsView.focus' : 'gitpod.ports.reveal' ;
692
+
693
+ portsStatusBarItem . command = ( await getPortsViewExperimentEnable ( ) ) ? 'gitpod.portsView.focus' : 'gitpod.ports.reveal' ;
684
694
portsStatusBarItem . show ( ) ;
685
695
}
686
696
updateStatusBar ( ) ;
@@ -820,11 +830,11 @@ function registerPorts(context: GitpodExtensionContext): void {
820
830
vscode . commands . executeCommand ( 'gitpod.api.connectLocalApp' , apiPort ) ;
821
831
}
822
832
} ) ) ;
823
- vscode . workspace . onDidChangeConfiguration ( ( e : vscode . ConfigurationChangeEvent ) => {
833
+ vscode . workspace . onDidChangeConfiguration ( async ( e : vscode . ConfigurationChangeEvent ) => {
824
834
if ( ! e . affectsConfiguration ( 'gitpod.experimental.portsView.enabled' ) ) {
825
835
return ;
826
836
}
827
- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
837
+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
828
838
vscode . commands . executeCommand ( 'setContext' , 'gitpod.portsView.visible' , isPortsViewExperimentEnable ) ;
829
839
gitpodWorkspaceTreeDataProvider . updateIsPortsViewExperimentEnable ( isPortsViewExperimentEnable ?? false ) ;
830
840
updateStatusBar ( ) ;
0 commit comments