@@ -21,9 +21,11 @@ import { LSNotSupportedDiagnosticServiceId } from '../../client/application/diag
2121import  {  IDiagnostic ,  IDiagnosticsService  }  from  '../../client/application/diagnostics/types' ; 
2222import  {  IApplicationShell ,  ICommandManager ,  IWorkspaceService  }  from  '../../client/common/application/types' ; 
2323import  {  IPlatformService  }  from  '../../client/common/platform/types' ; 
24- import  {  IConfigurationService ,  IDisposable ,  IDisposableRegistry ,  IOutputChannel ,  IPythonSettings ,  Resource  }  from  '../../client/common/types' ; 
24+ import  {  IConfigurationService ,  IDisposable ,  IDisposableRegistry ,  IOutputChannel ,  IPersistentState ,   IPersistentStateFactory ,   IPythonSettings ,  Resource  }  from  '../../client/common/types' ; 
2525import  {  IServiceContainer  }  from  '../../client/ioc/types' ; 
2626
27+ // tslint:disable:no-any 
28+ 
2729suite ( 'Activation - ActivationService' ,  ( )  =>  { 
2830 [ true ,  false ] . forEach ( jediIsEnabled  =>  { 
2931 suite ( `Jedi is ${ jediIsEnabled  ? 'enabled'  : 'disabled' }  ,  ( )  =>  { 
@@ -34,12 +36,16 @@ suite('Activation - ActivationService', () => {
3436 let  workspaceService : TypeMoq . IMock < IWorkspaceService > ; 
3537 let  platformService : TypeMoq . IMock < IPlatformService > ; 
3638 let  lsNotSupportedDiagnosticService : TypeMoq . IMock < IDiagnosticsService > ; 
39+  let  stateFactory : TypeMoq . IMock < IPersistentStateFactory > ; 
40+  let  state : TypeMoq . IMock < IPersistentState < boolean  |  undefined > > ; 
3741 setup ( ( )  =>  { 
3842 serviceContainer  =  TypeMoq . Mock . ofType < IServiceContainer > ( ) ; 
3943 appShell  =  TypeMoq . Mock . ofType < IApplicationShell > ( ) ; 
4044 workspaceService  =  TypeMoq . Mock . ofType < IWorkspaceService > ( ) ; 
4145 cmdManager  =  TypeMoq . Mock . ofType < ICommandManager > ( ) ; 
4246 platformService  =  TypeMoq . Mock . ofType < IPlatformService > ( ) ; 
47+  stateFactory  =  TypeMoq . Mock . ofType < IPersistentStateFactory > ( ) ; 
48+  state  =  TypeMoq . Mock . ofType < IPersistentState < boolean  |  undefined > > ( ) ; 
4349 const  configService  =  TypeMoq . Mock . ofType < IConfigurationService > ( ) ; 
4450 pythonSettings  =  TypeMoq . Mock . ofType < IPythonSettings > ( ) ; 
4551 const  langFolderServiceMock  =  TypeMoq . Mock . ofType < ILanguageServerFolderService > ( ) ; 
@@ -54,7 +60,10 @@ suite('Activation - ActivationService', () => {
5460 langFolderServiceMock 
5561 . setup ( l  =>  l . getCurrentLanguageServerDirectory ( ) ) 
5662 . returns ( ( )  =>  Promise . resolve ( folderVer ) ) ; 
57- 
63+  stateFactory . setup ( f  =>  f . createGlobalPersistentState ( TypeMoq . It . isValue ( 'SWITCH_LS' ) ,  TypeMoq . It . isAny ( ) ,  TypeMoq . It . isAny ( ) ) ) 
64+  . returns ( ( )  =>  state . object ) ; 
65+  state . setup ( s  =>  s . value ) . returns ( ( )  =>  undefined ) ; 
66+  state . setup ( s  =>  s . updateValue ( TypeMoq . It . isAny ( ) ) ) . returns ( ( )  =>  Promise . resolve ( ) ) ; 
5867 const  output  =  TypeMoq . Mock . ofType < IOutputChannel > ( ) ; 
5968 serviceContainer 
6069 . setup ( c  =>  c . get ( TypeMoq . It . isValue ( IOutputChannel ) ,  TypeMoq . It . isAny ( ) ) ) 
@@ -101,7 +110,7 @@ suite('Activation - ActivationService', () => {
101110 if  ( lsSupported  &&  ! jediIsEnabled )  { 
102111 activatorName  =  LanguageServerActivator . DotNet ; 
103112 } 
104-  let  diagnostics   : IDiagnostic [ ] ; 
113+  let  diagnostics : IDiagnostic [ ] ; 
105114 if  ( ! lsSupported  &&  ! jediIsEnabled )  { 
106115 diagnostics  =  [ TypeMoq . It . isAny ( ) ] ; 
107116 }  else  { 
@@ -127,29 +136,29 @@ suite('Activation - ActivationService', () => {
127136 test ( 'LS is supported' ,  async  ( )  =>  { 
128137 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
129138 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
130-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
139+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
131140
132141 await  testActivation ( activationService ,  activator ,  true ) ; 
133142 } ) ; 
134143 test ( 'LS is not supported' ,  async  ( )  =>  { 
135144 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
136145 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
137-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
146+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
138147
139148 await  testActivation ( activationService ,  activator ,  false ) ; 
140149 } ) ; 
141150
142151 test ( 'Activatory must be activated' ,  async  ( )  =>  { 
143152 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
144153 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
145-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
154+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
146155
147156 await  testActivation ( activationService ,  activator ) ; 
148157 } ) ; 
149158 test ( 'Activatory must be deactivated' ,  async  ( )  =>  { 
150159 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
151160 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
152-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
161+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
153162
154163 await  testActivation ( activationService ,  activator ) ; 
155164
@@ -171,7 +180,7 @@ suite('Activation - ActivationService', () => {
171180
172181 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabledValueInSetting ) ; 
173182 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
174-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
183+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
175184
176185 workspaceService . verifyAll ( ) ; 
177186 await  testActivation ( activationService ,  activator ) ; 
@@ -208,7 +217,7 @@ suite('Activation - ActivationService', () => {
208217
209218 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabledValueInSetting ) ; 
210219 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
211-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
220+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
212221
213222 workspaceService . verifyAll ( ) ; 
214223 await  testActivation ( activationService ,  activator ) ; 
@@ -244,7 +253,7 @@ suite('Activation - ActivationService', () => {
244253
245254 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
246255 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
247-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
256+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
248257
249258 workspaceService . verifyAll ( ) ; 
250259 await  testActivation ( activationService ,  activator ) ; 
@@ -279,7 +288,7 @@ suite('Activation - ActivationService', () => {
279288
280289 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
281290 const  activator  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
282-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
291+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
283292
284293 workspaceService . verifyAll ( ) ; 
285294 await  testActivation ( activationService ,  activator ) ; 
@@ -304,12 +313,42 @@ suite('Activation - ActivationService', () => {
304313 appShell . verifyAll ( ) ; 
305314 cmdManager . verifyAll ( ) ; 
306315 } ) ; 
316+  test ( 'Track current LS usage for first usage' ,  async  ( )  =>  { 
317+  state . reset ( ) ; 
318+  state . setup ( s  =>  s . value ) . returns ( ( )  =>  undefined ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
319+  state . setup ( s  =>  s . updateValue ( TypeMoq . It . isValue ( true ) ) ) . returns ( ( )  =>  Promise . resolve ( ) ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
320+ 
321+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,  stateFactory . object ) ; 
322+  await  activationService . trackLangaugeServerSwitch ( true ) ; 
323+ 
324+  state . verifyAll ( ) ; 
325+  } ) ; 
326+  test ( 'Track switch to LS' ,  async  ( )  =>  { 
327+  state . reset ( ) ; 
328+  state . setup ( s  =>  s . value ) . returns ( ( )  =>  true ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
329+  state . setup ( s  =>  s . updateValue ( TypeMoq . It . isValue ( false ) ) ) . returns ( ( )  =>  Promise . resolve ( ) ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
330+ 
331+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,  stateFactory . object ) ; 
332+  await  activationService . trackLangaugeServerSwitch ( false ) ; 
333+ 
334+  state . verify ( s  =>  s . updateValue ( TypeMoq . It . isValue ( false ) ) ,  TypeMoq . Times . once ( ) ) ; 
335+  } ) ; 
336+  test ( 'Track switch to Jedi' ,  async  ( )  =>  { 
337+  state . reset ( ) ; 
338+  state . setup ( s  =>  s . value ) . returns ( ( )  =>  false ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
339+  state . setup ( s  =>  s . updateValue ( TypeMoq . It . isValue ( true ) ) ) . returns ( ( )  =>  Promise . resolve ( ) ) . verifiable ( TypeMoq . Times . once ( ) ) ; 
340+ 
341+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,  stateFactory . object ) ; 
342+  await  activationService . trackLangaugeServerSwitch ( true ) ; 
343+ 
344+  state . verify ( s  =>  s . updateValue ( TypeMoq . It . isValue ( true ) ) ,  TypeMoq . Times . once ( ) ) ; 
345+  } ) ; 
307346 if  ( ! jediIsEnabled )  { 
308347 test ( 'Revert to jedi when LS activation fails' ,  async  ( )  =>  { 
309348 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
310349 const  activatorDotNet  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
311350 const  activatorJedi  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
312-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
351+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
313352 const  diagnostics : IDiagnostic [ ]  =  [ ] ; 
314353 lsNotSupportedDiagnosticService 
315354 . setup ( l  =>  l . diagnose ( undefined ) ) 
@@ -388,7 +427,7 @@ suite('Activation - ActivationService', () => {
388427 . callback ( cb  =>  ( workspaceFoldersChangedHandler  =  cb ) ) 
389428 . returns ( ( )  =>  TypeMoq . Mock . ofType < IDisposable > ( ) . object ) 
390429 . verifiable ( TypeMoq . Times . once ( ) ) ; 
391-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
430+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
392431 workspaceService . verifyAll ( ) ; 
393432 expect ( workspaceFoldersChangedHandler ) . not . to . be . equal ( undefined ,  'Handler not set' ) ; 
394433 const  folder1  =  {  name : 'one' ,  uri : Uri . parse ( 'one' ) ,  index : 1  } ; 
@@ -430,7 +469,7 @@ suite('Activation - ActivationService', () => {
430469 test ( 'Jedi is only activated once' ,  async  ( )  =>  { 
431470 pythonSettings . setup ( p  =>  p . jediEnabled ) . returns ( ( )  =>  jediIsEnabled ) ; 
432471 const  activator1  =  TypeMoq . Mock . ofType < ILanguageServerActivator > ( ) ; 
433-  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ) ; 
472+  const  activationService  =  new  LanguageServerExtensionActivationService ( serviceContainer . object ,   stateFactory . object ) ; 
434473 const  folder1  =  {  name : 'one' ,  uri : Uri . parse ( 'one' ) ,  index : 1  } ; 
435474 const  folder2  =  {  name : 'two' ,  uri : Uri . parse ( 'two' ) ,  index : 2  } ; 
436475 serviceContainer 
0 commit comments