@@ -25,6 +25,7 @@ import { getManifest } from './util/extensionManagmentUtill';
2525import { GitpodWorkspacePort , PortInfo , iconStatusMap } from './util/port' ;
2626import { ReleaseNotes } from './releaseNotes' ;
2727import { registerWelcomeWalkthroughContribution , WELCOME_WALKTROUGH_KEY } from './welcomeWalktrough' ;
28+ import { ExperimentalSettings , isUserOverrideSetting } from './experiments' ;
2829
2930let gitpodContext : GitpodExtensionContext | undefined ;
3031export async function activate ( context : vscode . ExtensionContext ) {
@@ -516,8 +517,16 @@ function getNonce() {
516517
517518interface PortItem { port : GitpodWorkspacePort ; isWebview ?: boolean }
518519
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 ( ) ;
521530
522531 const portMap = new Map < number , GitpodWorkspacePort > ( ) ;
523532 const tunnelMap = new Map < number , vscode . TunnelDescription > ( ) ;
@@ -577,6 +586,7 @@ function registerPorts(context: GitpodExtensionContext): void {
577586 }
578587 } ) ;
579588 }
589+
580590 context . subscriptions . push ( observePortsStatus ( ) ) ;
581591 context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.resolveExternalPort' , ( portNumber : number ) => {
582592 // eslint-disable-next-line no-async-promise-executor
@@ -616,14 +626,14 @@ function registerPorts(context: GitpodExtensionContext): void {
616626 context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePrivate' , ( { port, isWebview } : PortItem ) => {
617627 context . fireAnalyticsEvent ( {
618628 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' ) ) }
620630 } ) ;
621631 return port . setPortVisibility ( 'private' ) ;
622632 } ) ) ;
623633 context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.makePublic' , ( { port, isWebview } : PortItem ) => {
624634 context . fireAnalyticsEvent ( {
625635 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' ) ) }
627637 } ) ;
628638 return port . setPortVisibility ( 'public' ) ;
629639 } ) ) ;
@@ -636,14 +646,14 @@ function registerPorts(context: GitpodExtensionContext): void {
636646 context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.preview' , ( { port, isWebview } : PortItem ) => {
637647 context . fireAnalyticsEvent ( {
638648 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' ) ) }
640650 } ) ;
641651 return openPreview ( port ) ;
642652 } ) ) ;
643653 context . subscriptions . push ( vscode . commands . registerCommand ( 'gitpod.ports.openBrowser' , ( { port, isWebview } : PortItem ) => {
644654 context . fireAnalyticsEvent ( {
645655 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' ) ) }
647657 } ) ;
648658 return openExternal ( port ) ;
649659 } ) ) ;
@@ -657,7 +667,7 @@ function registerPorts(context: GitpodExtensionContext): void {
657667
658668 const portsStatusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ;
659669 context . subscriptions . push ( portsStatusBarItem ) ;
660- function updateStatusBar ( ) : void {
670+ async function updateStatusBar ( ) : Promise < void > {
661671 const exposedPorts : number [ ] = [ ] ;
662672
663673 for ( const port of portMap . values ( ) ) {
@@ -679,8 +689,8 @@ function registerPorts(context: GitpodExtensionContext): void {
679689
680690 portsStatusBarItem . text = text ;
681691 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' ;
684694 portsStatusBarItem . show ( ) ;
685695 }
686696 updateStatusBar ( ) ;
@@ -820,11 +830,11 @@ function registerPorts(context: GitpodExtensionContext): void {
820830 vscode . commands . executeCommand ( 'gitpod.api.connectLocalApp' , apiPort ) ;
821831 }
822832 } ) ) ;
823- vscode . workspace . onDidChangeConfiguration ( ( e : vscode . ConfigurationChangeEvent ) => {
833+ vscode . workspace . onDidChangeConfiguration ( async ( e : vscode . ConfigurationChangeEvent ) => {
824834 if ( ! e . affectsConfiguration ( 'gitpod.experimental.portsView.enabled' ) ) {
825835 return ;
826836 }
827- const isPortsViewExperimentEnable = vscode . workspace . getConfiguration ( 'gitpod.experimental.portsView' ) . get < boolean > ( 'enabled' ) ;
837+ const isPortsViewExperimentEnable = await getPortsViewExperimentEnable ( ) ;
828838 vscode . commands . executeCommand ( 'setContext' , 'gitpod.portsView.visible' , isPortsViewExperimentEnable ) ;
829839 gitpodWorkspaceTreeDataProvider . updateIsPortsViewExperimentEnable ( isPortsViewExperimentEnable ?? false ) ;
830840 updateStatusBar ( ) ;
0 commit comments