@@ -9,8 +9,10 @@ import { LSNotSupportedDiagnosticServiceId } from '../application/diagnostics/ch
9
9
import { IDiagnosticsService } from '../application/diagnostics/types' ;
10
10
import { IApplicationShell , ICommandManager , IWorkspaceService } from '../common/application/types' ;
11
11
import { STANDARD_OUTPUT_CHANNEL } from '../common/constants' ;
12
+ import { LSControl , LSEnabled } from '../common/experimentGroups' ;
12
13
import '../common/extensions' ;
13
- import { IConfigurationService , IDisposableRegistry , IOutputChannel , IPersistentStateFactory , IPythonSettings , Resource } from '../common/types' ;
14
+ import { traceError } from '../common/logger' ;
15
+ import { IConfigurationService , IDisposableRegistry , IExperimentsManager , IOutputChannel , IPersistentStateFactory , IPythonSettings , Resource } from '../common/types' ;
14
16
import { swallowExceptions } from '../common/utils/decorators' ;
15
17
import { IServiceContainer } from '../ioc/types' ;
16
18
import { sendTelemetryEvent } from '../telemetry' ;
@@ -33,7 +35,8 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
33
35
private resource ! : Resource ;
34
36
35
37
constructor ( @inject ( IServiceContainer ) private serviceContainer : IServiceContainer ,
36
- @inject ( IPersistentStateFactory ) private stateFactory : IPersistentStateFactory ) {
38
+ @inject ( IPersistentStateFactory ) private stateFactory : IPersistentStateFactory ,
39
+ @inject ( IExperimentsManager ) private readonly abExperiments : IExperimentsManager ) {
37
40
this . workspaceService = this . serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
38
41
this . output = this . serviceContainer . get < OutputChannel > ( IOutputChannel , STANDARD_OUTPUT_CHANNEL ) ;
39
42
this . appShell = this . serviceContainer . get < IApplicationShell > ( IApplicationShell ) ;
@@ -113,6 +116,39 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
113
116
sendTelemetryEvent ( EventName . PYTHON_LANGUAGE_SERVER_SWITCHED , undefined , { change : message } ) ;
114
117
}
115
118
}
119
+
120
+ /**
121
+ * Checks if user has not manually set `jediEnabled` setting
122
+ * @param resource
123
+ * @returns `true` if user has NOT manually added the setting and is using default configuration, `false` if user has `jediEnabled` setting added
124
+ */
125
+ public isJediUsingDefaultConfiguration ( resource ?: Uri ) : boolean {
126
+ const settings = this . workspaceService . getConfiguration ( 'python' , resource ) . inspect < boolean > ( 'jediEnabled' ) ;
127
+ if ( ! settings ) {
128
+ traceError ( 'WorkspaceConfiguration.inspect returns `undefined` for setting `python.jediEnabled`' ) ;
129
+ return false ;
130
+ }
131
+ return ( settings . globalValue === undefined && settings . workspaceValue === undefined && settings . workspaceFolderValue === undefined ) ;
132
+ }
133
+
134
+ /**
135
+ * Checks if user is using Jedi as intellisense
136
+ * @returns `true` if user is using jedi, `false` if user is using language server
137
+ */
138
+ public useJedi ( ) : boolean {
139
+ if ( this . isJediUsingDefaultConfiguration ( ) ) {
140
+ if ( this . abExperiments . inExperiment ( LSEnabled ) ) {
141
+ return false ;
142
+ }
143
+ // Send telemetry if user is in control group
144
+ this . abExperiments . sendTelemetryIfInExperiment ( LSControl ) ;
145
+ }
146
+ const configurationService = this . serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
147
+ const enabled = configurationService . getSettings ( this . resource ) . jediEnabled ;
148
+ this . trackLangaugeServerSwitch ( enabled ) . ignoreErrors ( ) ;
149
+ return enabled ;
150
+ }
151
+
116
152
protected onWorkspaceFoldersChanged ( ) {
117
153
//If an activated workspace folder was removed, dispose its activator
118
154
const workspaceKeys = this . workspaceService . workspaceFolders ! . map ( workspaceFolder => this . getWorkspacePathKey ( workspaceFolder . uri ) ) ;
@@ -153,12 +189,6 @@ export class LanguageServerExtensionActivationService implements IExtensionActiv
153
189
this . serviceContainer . get < ICommandManager > ( ICommandManager ) . executeCommand ( 'workbench.action.reloadWindow' ) ;
154
190
}
155
191
}
156
- private useJedi ( ) : boolean {
157
- const configurationService = this . serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
158
- const enabled = configurationService . getSettings ( this . resource ) . jediEnabled ;
159
- this . trackLangaugeServerSwitch ( enabled ) . ignoreErrors ( ) ;
160
- return enabled ;
161
- }
162
192
private getWorkspacePathKey ( resource : Resource ) : string {
163
193
return this . workspaceService . getWorkspaceFolderIdentifier ( resource , workspacePathNameForGlobalWorkspaces ) ;
164
194
}
0 commit comments