1
1
import { inject , injectable } from 'inversify' ;
2
2
import { Disposable , StatusBarAlignment , StatusBarItem , Uri } from 'vscode' ;
3
+ import { IExtensionSingleActivationService } from '../../activation/types' ;
3
4
import { IApplicationShell , IWorkspaceService } from '../../common/application/types' ;
5
+ import { Commands } from '../../common/constants' ;
6
+ import { InterpreterStatusBarPosition } from '../../common/experiments/groups' ;
4
7
import '../../common/extensions' ;
5
- import { IDisposableRegistry , IPathUtils , Resource } from '../../common/types' ;
8
+ import { IDisposableRegistry , IExperimentService , IPathUtils , Resource } from '../../common/types' ;
6
9
import { Interpreters } from '../../common/utils/localize' ;
7
10
import { IServiceContainer } from '../../ioc/types' ;
8
11
import { traceLog } from '../../logging' ;
@@ -20,8 +23,12 @@ import {
20
23
*/
21
24
const STATUS_BAR_ITEM_PRIORITY = 100.09999 ;
22
25
@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 ;
25
32
private readonly helper : IInterpreterHelper ;
26
33
private readonly workspaceService : IWorkspaceService ;
27
34
private readonly pathUtils : IPathUtils ;
@@ -31,26 +38,36 @@ export class InterpreterDisplay implements IInterpreterDisplay {
31
38
private interpreterPath : string | undefined ;
32
39
private statusBarCanBeDisplayed ?: boolean ;
33
40
private visibilityFilters : IInterpreterStatusbarVisibilityFilter [ ] = [ ] ;
41
+ private disposableRegistry : Disposable [ ] ;
42
+ private experiments : IExperimentService ;
34
43
35
44
constructor ( @inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ) {
36
45
this . helper = serviceContainer . get < IInterpreterHelper > ( IInterpreterHelper ) ;
37
46
this . workspaceService = serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
38
47
this . pathUtils = serviceContainer . get < IPathUtils > ( IPathUtils ) ;
39
48
this . interpreterService = serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
40
49
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 ) ;
47
51
48
52
this . interpreterService . onDidChangeInterpreterInformation (
49
53
this . onDidChangeInterpreterInformation ,
50
54
this ,
51
- disposableRegistry ,
55
+ this . disposableRegistry ,
52
56
) ;
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 ) ;
53
69
}
70
+
54
71
public async refresh ( resource ?: Uri ) {
55
72
// Use the workspace Uri if available
56
73
if ( resource && this . workspaceService . getWorkspaceFolder ( resource ) ) {
@@ -88,7 +105,11 @@ export class InterpreterDisplay implements IInterpreterDisplay {
88
105
) ;
89
106
this . interpreterPath = interpreter . path ;
90
107
}
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 ;
92
113
this . currentlySelectedInterpreterPath = interpreter . path ;
93
114
} else {
94
115
this . statusBar . tooltip = '' ;
0 commit comments