@@ -24,6 +24,7 @@ import { NoneLSExtensionManager } from '../../client/languageServer/noneLSExtens
24
24
import { PylanceLSExtensionManager } from '../../client/languageServer/pylanceLSExtensionManager' ;
25
25
import { LanguageServerWatcher } from '../../client/languageServer/watcher' ;
26
26
import * as Logging from '../../client/logging' ;
27
+ import { PythonEnvironment } from '../../client/pythonEnvironments/info' ;
27
28
28
29
suite ( 'Language server watcher' , ( ) => {
29
30
let watcher : LanguageServerWatcher ;
@@ -47,6 +48,9 @@ suite('Language server watcher', () => {
47
48
} as unknown ) as IInterpreterPathService ,
48
49
( {
49
50
getActiveInterpreter : ( ) => 'python' ,
51
+ onDidChangeInterpreterInformation : ( ) => {
52
+ /* do nothing */
53
+ } ,
50
54
} as unknown ) as IInterpreterService ,
51
55
{ } as IEnvironmentVariablesProvider ,
52
56
( {
@@ -95,7 +99,11 @@ suite('Language server watcher', () => {
95
99
/* do nothing */
96
100
} ,
97
101
} as unknown ) as IInterpreterPathService ,
98
- { } as IInterpreterService ,
102
+ ( {
103
+ onDidChangeInterpreterInformation : ( ) => {
104
+ /* do nothing */
105
+ } ,
106
+ } as unknown ) as IInterpreterService ,
99
107
{ } as IEnvironmentVariablesProvider ,
100
108
( {
101
109
isTrusted : true ,
@@ -138,7 +146,11 @@ suite('Language server watcher', () => {
138
146
/* do nothing */
139
147
} ,
140
148
} as unknown ) as IInterpreterPathService ,
141
- { } as IInterpreterService ,
149
+ ( {
150
+ onDidChangeInterpreterInformation : ( ) => {
151
+ /* do nothing */
152
+ } ,
153
+ } as unknown ) as IInterpreterService ,
142
154
{ } as IEnvironmentVariablesProvider ,
143
155
( {
144
156
isTrusted : false ,
@@ -180,6 +192,9 @@ suite('Language server watcher', () => {
180
192
181
193
const interpreterService = ( {
182
194
getActiveInterpreter : getActiveInterpreterStub ,
195
+ onDidChangeInterpreterInformation : ( ) => {
196
+ /* do nothing */
197
+ } ,
183
198
} as unknown ) as IInterpreterService ;
184
199
185
200
watcher = new LanguageServerWatcher (
@@ -277,6 +292,9 @@ suite('Language server watcher', () => {
277
292
} as unknown ) as IInterpreterPathService ,
278
293
( {
279
294
getActiveInterpreter : ( ) => 'python' ,
295
+ onDidChangeInterpreterInformation : ( ) => {
296
+ /* do nothing */
297
+ } ,
280
298
} as unknown ) as IInterpreterService ,
281
299
{ } as IEnvironmentVariablesProvider ,
282
300
( {
@@ -360,6 +378,9 @@ suite('Language server watcher', () => {
360
378
} as unknown ) as IInterpreterPathService ,
361
379
( {
362
380
getActiveInterpreter : ( ) => 'python' ,
381
+ onDidChangeInterpreterInformation : ( ) => {
382
+ /* do nothing */
383
+ } ,
363
384
} as unknown ) as IInterpreterService ,
364
385
{ } as IEnvironmentVariablesProvider ,
365
386
workspaceService ,
@@ -426,6 +447,9 @@ suite('Language server watcher', () => {
426
447
} as unknown ) as IInterpreterPathService ,
427
448
( {
428
449
getActiveInterpreter : ( ) => 'python' ,
450
+ onDidChangeInterpreterInformation : ( ) => {
451
+ /* do nothing */
452
+ } ,
429
453
} as unknown ) as IInterpreterService ,
430
454
{ } as IEnvironmentVariablesProvider ,
431
455
workspaceService ,
@@ -477,6 +501,9 @@ suite('Language server watcher', () => {
477
501
} as unknown ) as IInterpreterPathService ,
478
502
( {
479
503
getActiveInterpreter : ( ) => ( { version : { major : 2 , minor : 7 } } ) ,
504
+ onDidChangeInterpreterInformation : ( ) => {
505
+ /* do nothing */
506
+ } ,
480
507
} as unknown ) as IInterpreterService ,
481
508
{ } as IEnvironmentVariablesProvider ,
482
509
( {
@@ -535,6 +562,9 @@ suite('Language server watcher', () => {
535
562
} as unknown ) as IInterpreterPathService ,
536
563
( {
537
564
getActiveInterpreter : ( ) => ( { version : { major : 2 , minor : 7 } } ) ,
565
+ onDidChangeInterpreterInformation : ( ) => {
566
+ /* do nothing */
567
+ } ,
538
568
} as unknown ) as IInterpreterService ,
539
569
{ } as IEnvironmentVariablesProvider ,
540
570
( {
@@ -590,6 +620,9 @@ suite('Language server watcher', () => {
590
620
} as unknown ) as IInterpreterPathService ,
591
621
( {
592
622
getActiveInterpreter : ( ) => ( { version : { major : 2 , minor : 7 } } ) ,
623
+ onDidChangeInterpreterInformation : ( ) => {
624
+ /* do nothing */
625
+ } ,
593
626
} as unknown ) as IInterpreterService ,
594
627
{ } as IEnvironmentVariablesProvider ,
595
628
( {
@@ -673,6 +706,9 @@ suite('Language server watcher', () => {
673
706
} as unknown ) as IInterpreterPathService ,
674
707
( {
675
708
getActiveInterpreter : getActiveInterpreterStub ,
709
+ onDidChangeInterpreterInformation : ( ) => {
710
+ /* do nothing */
711
+ } ,
676
712
} as unknown ) as IInterpreterService ,
677
713
{ } as IEnvironmentVariablesProvider ,
678
714
( {
@@ -757,6 +793,9 @@ suite('Language server watcher', () => {
757
793
} as unknown ) as IInterpreterPathService ,
758
794
( {
759
795
getActiveInterpreter : ( ) => ( { version : { major : 3 , minor : 7 } } ) ,
796
+ onDidChangeInterpreterInformation : ( ) => {
797
+ /* do nothing */
798
+ } ,
760
799
} as unknown ) as IInterpreterService ,
761
800
{ } as IEnvironmentVariablesProvider ,
762
801
workspaceService ,
@@ -792,4 +831,165 @@ suite('Language server watcher', () => {
792
831
assert . ok ( stopLanguageServerStub . notCalled === ! multiLS ) ;
793
832
} ) ;
794
833
} ) ;
834
+
835
+ test ( 'The language server should be restarted if the interpreter info changed' , async ( ) => {
836
+ const info = ( {
837
+ envPath : 'foo' ,
838
+ path : 'path/to/foo/bin/python' ,
839
+ } as unknown ) as PythonEnvironment ;
840
+
841
+ let onDidChangeInfoListener : ( event : PythonEnvironment ) => Promise < void > = ( ) => Promise . resolve ( ) ;
842
+
843
+ const interpreterService = ( {
844
+ onDidChangeInterpreterInformation : (
845
+ listener : ( event : PythonEnvironment ) => Promise < void > ,
846
+ thisArg : unknown ,
847
+ ) : void => {
848
+ onDidChangeInfoListener = listener . bind ( thisArg ) ;
849
+ } ,
850
+ getActiveInterpreter : ( ) => ( {
851
+ envPath : 'foo' ,
852
+ path : 'path/to/foo' ,
853
+ } ) ,
854
+ } as unknown ) as IInterpreterService ;
855
+
856
+ watcher = new LanguageServerWatcher (
857
+ ( {
858
+ get : ( ) => {
859
+ /* do nothing */
860
+ } ,
861
+ } as unknown ) as IServiceContainer ,
862
+ { } as ILanguageServerOutputChannel ,
863
+ {
864
+ getSettings : ( ) => ( { languageServer : LanguageServerType . None } ) ,
865
+ } as IConfigurationService ,
866
+ { } as IExperimentService ,
867
+ ( {
868
+ getActiveWorkspaceUri : ( ) => undefined ,
869
+ } as unknown ) as IInterpreterHelper ,
870
+ ( {
871
+ onDidChange : ( ) => {
872
+ /* do nothing */
873
+ } ,
874
+ } as unknown ) as IInterpreterPathService ,
875
+ interpreterService ,
876
+ ( {
877
+ onDidEnvironmentVariablesChange : ( ) => {
878
+ /* do nothing */
879
+ } ,
880
+ } as unknown ) as IEnvironmentVariablesProvider ,
881
+ ( {
882
+ isTrusted : true ,
883
+ getWorkspaceFolder : ( uri : Uri ) => ( { uri } ) ,
884
+ onDidChangeConfiguration : ( ) => {
885
+ /* do nothing */
886
+ } ,
887
+ onDidChangeWorkspaceFolders : ( ) => {
888
+ /* do nothing */
889
+ } ,
890
+ } as unknown ) as IWorkspaceService ,
891
+ ( {
892
+ registerCommand : ( ) => {
893
+ /* do nothing */
894
+ } ,
895
+ } as unknown ) as ICommandManager ,
896
+ { } as IFileSystem ,
897
+ ( {
898
+ getExtension : ( ) => undefined ,
899
+ onDidChange : ( ) => {
900
+ /* do nothing */
901
+ } ,
902
+ } as unknown ) as IExtensions ,
903
+ { } as IApplicationShell ,
904
+ [ ] as Disposable [ ] ,
905
+ ) ;
906
+
907
+ const startLanguageServerSpy = sandbox . spy ( watcher , 'startLanguageServer' ) ;
908
+
909
+ await watcher . startLanguageServer ( LanguageServerType . None ) ;
910
+
911
+ await onDidChangeInfoListener ( info ) ;
912
+
913
+ // Check that startLanguageServer was called twice: Once above, and once after the interpreter info changed.
914
+ assert . ok ( startLanguageServerSpy . calledTwice ) ;
915
+ } ) ;
916
+
917
+ test ( 'The language server should not be restarted if the interpreter info did not change' , async ( ) => {
918
+ const info = ( {
919
+ envPath : 'foo' ,
920
+ path : 'path/to/foo' ,
921
+ } as unknown ) as PythonEnvironment ;
922
+
923
+ let onDidChangeInfoListener : ( event : PythonEnvironment ) => Promise < void > = ( ) => Promise . resolve ( ) ;
924
+
925
+ const interpreterService = ( {
926
+ onDidChangeInterpreterInformation : (
927
+ listener : ( event : PythonEnvironment ) => Promise < void > ,
928
+ thisArg : unknown ,
929
+ ) : void => {
930
+ onDidChangeInfoListener = listener . bind ( thisArg ) ;
931
+ } ,
932
+ getActiveInterpreter : ( ) => info ,
933
+ } as unknown ) as IInterpreterService ;
934
+
935
+ watcher = new LanguageServerWatcher (
936
+ ( {
937
+ get : ( ) => {
938
+ /* do nothing */
939
+ } ,
940
+ } as unknown ) as IServiceContainer ,
941
+ { } as ILanguageServerOutputChannel ,
942
+ {
943
+ getSettings : ( ) => ( { languageServer : LanguageServerType . None } ) ,
944
+ } as IConfigurationService ,
945
+ { } as IExperimentService ,
946
+ ( {
947
+ getActiveWorkspaceUri : ( ) => undefined ,
948
+ } as unknown ) as IInterpreterHelper ,
949
+ ( {
950
+ onDidChange : ( ) => {
951
+ /* do nothing */
952
+ } ,
953
+ } as unknown ) as IInterpreterPathService ,
954
+ interpreterService ,
955
+ ( {
956
+ onDidEnvironmentVariablesChange : ( ) => {
957
+ /* do nothing */
958
+ } ,
959
+ } as unknown ) as IEnvironmentVariablesProvider ,
960
+ ( {
961
+ isTrusted : true ,
962
+ getWorkspaceFolder : ( uri : Uri ) => ( { uri } ) ,
963
+ onDidChangeConfiguration : ( ) => {
964
+ /* do nothing */
965
+ } ,
966
+ onDidChangeWorkspaceFolders : ( ) => {
967
+ /* do nothing */
968
+ } ,
969
+ } as unknown ) as IWorkspaceService ,
970
+ ( {
971
+ registerCommand : ( ) => {
972
+ /* do nothing */
973
+ } ,
974
+ } as unknown ) as ICommandManager ,
975
+ { } as IFileSystem ,
976
+ ( {
977
+ getExtension : ( ) => undefined ,
978
+ onDidChange : ( ) => {
979
+ /* do nothing */
980
+ } ,
981
+ } as unknown ) as IExtensions ,
982
+ { } as IApplicationShell ,
983
+ [ ] as Disposable [ ] ,
984
+ ) ;
985
+
986
+ const startLanguageServerSpy = sandbox . spy ( watcher , 'startLanguageServer' ) ;
987
+
988
+ await watcher . startLanguageServer ( LanguageServerType . None ) ;
989
+
990
+ await onDidChangeInfoListener ( info ) ;
991
+
992
+ // Check that startLanguageServer was called once: Only when startLanguageServer() was called above.
993
+ assert . ok ( startLanguageServerSpy . calledOnce ) ;
994
+ } ) ;
795
995
} ) ;
0 commit comments