11import { inject , injectable } from 'inversify' ;
22import { Disposable , StatusBarAlignment , StatusBarItem , Uri } from 'vscode' ;
3+ import { IExtensionSingleActivationService } from '../../activation/types' ;
34import { IApplicationShell , IWorkspaceService } from '../../common/application/types' ;
5+ import { Commands } from '../../common/constants' ;
6+ import { InterpreterStatusBarPosition } from '../../common/experiments/groups' ;
47import '../../common/extensions' ;
5- import { IDisposableRegistry , IPathUtils , Resource } from '../../common/types' ;
8+ import { IDisposableRegistry , IExperimentService , IPathUtils , Resource } from '../../common/types' ;
69import { Interpreters } from '../../common/utils/localize' ;
710import { IServiceContainer } from '../../ioc/types' ;
811import { traceLog } from '../../logging' ;
@@ -20,8 +23,12 @@ import {
2023 */
2124const STATUS_BAR_ITEM_PRIORITY = 100.09999 ;
2225@injectable ( )
23- export class InterpreterDisplay implements IInterpreterDisplay {
24- private readonly statusBar : StatusBarItem ;
26+ export class InterpreterDisplay implements IInterpreterDisplay , IExtensionSingleActivationService {
27+ public supportedWorkspaceTypes : { untrustedWorkspace : boolean ; virtualWorkspace : boolean } = {
28+ untrustedWorkspace : false ,
29+ virtualWorkspace : true ,
30+ } ;
31+ private statusBar ! : StatusBarItem ;
2532 private readonly helper : IInterpreterHelper ;
2633 private readonly workspaceService : IWorkspaceService ;
2734 private readonly pathUtils : IPathUtils ;
@@ -31,26 +38,36 @@ export class InterpreterDisplay implements IInterpreterDisplay {
3138 private interpreterPath : string | undefined ;
3239 private statusBarCanBeDisplayed ?: boolean ;
3340 private visibilityFilters : IInterpreterStatusbarVisibilityFilter [ ] = [ ] ;
41+ private disposableRegistry : Disposable [ ] ;
42+ private experiments : IExperimentService ;
3443
3544 constructor ( @inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ) {
3645 this . helper = serviceContainer . get < IInterpreterHelper > ( IInterpreterHelper ) ;
3746 this . workspaceService = serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
3847 this . pathUtils = serviceContainer . get < IPathUtils > ( IPathUtils ) ;
3948 this . interpreterService = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
4049
41- const application = serviceContainer . get < IApplicationShell > ( IApplicationShell ) ;
42- const disposableRegistry = serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
43-
44- this . statusBar = application . createStatusBarItem ( StatusBarAlignment . Right , STATUS_BAR_ITEM_PRIORITY ) ;
45- this . statusBar . command = 'python.setInterpreter' ;
46- disposableRegistry . push ( this . statusBar ) ;
50+ this . disposableRegistry = serviceContainer . get < Disposable [ ] > ( IDisposableRegistry ) ;
4751
4852 this . interpreterService . onDidChangeInterpreterInformation (
4953 this . onDidChangeInterpreterInformation ,
5054 this ,
51- disposableRegistry ,
55+ this . disposableRegistry ,
5256 ) ;
57+ this . experiments = this . serviceContainer . get < IExperimentService > ( IExperimentService ) ;
58+ }
59+
60+ public async activate ( ) : Promise < void > {
61+ let [ alignment , priority ] = [ StatusBarAlignment . Left , < number | undefined > undefined ] ;
62+ if ( this . experiments . inExperimentSync ( InterpreterStatusBarPosition . Pinned ) ) {
63+ [ alignment , priority ] = [ StatusBarAlignment . Right , STATUS_BAR_ITEM_PRIORITY ] ;
64+ }
65+ const application = this . serviceContainer . get < IApplicationShell > ( IApplicationShell ) ;
66+ this . statusBar = application . createStatusBarItem ( alignment , priority ) ;
67+ this . statusBar . command = Commands . Set_Interpreter ;
68+ this . disposableRegistry . push ( this . statusBar ) ;
5369 }
70+
5471 public async refresh ( resource ?: Uri ) {
5572 // Use the workspace Uri if available
5673 if ( resource && this . workspaceService . getWorkspaceFolder ( resource ) ) {
@@ -88,7 +105,11 @@ export class InterpreterDisplay implements IInterpreterDisplay {
88105 ) ;
89106 this . interpreterPath = interpreter . path ;
90107 }
91- this . statusBar . text = interpreter . displayName ! . substring ( 'Python ' . length ) ;
108+ let text = interpreter . displayName ! ;
109+ if ( this . experiments . inExperimentSync ( InterpreterStatusBarPosition . Pinned ) ) {
110+ text = text . substring ( 'Python ' . length ) ;
111+ }
112+ this . statusBar . text = text ;
92113 this . currentlySelectedInterpreterPath = interpreter . path ;
93114 } else {
94115 this . statusBar . tooltip = '' ;
0 commit comments