@@ -992,4 +992,168 @@ suite('Language server watcher', () => {
992992 // Check that startLanguageServer was called once: Only when startLanguageServer() was called above.
993993 assert . ok ( startLanguageServerSpy . calledOnce ) ;
994994 } ) ;
995+
996+ test ( 'The language server should not be restarted if the interpreter info changed but the env path is an empty string' , async ( ) => {
997+ const info = ( {
998+ envPath : '' ,
999+ path : 'path/to/foo' ,
1000+ } as unknown ) as PythonEnvironment ;
1001+
1002+ let onDidChangeInfoListener : ( event : PythonEnvironment ) => Promise < void > = ( ) => Promise . resolve ( ) ;
1003+
1004+ const interpreterService = ( {
1005+ onDidChangeInterpreterInformation : (
1006+ listener : ( event : PythonEnvironment ) => Promise < void > ,
1007+ thisArg : unknown ,
1008+ ) : void => {
1009+ onDidChangeInfoListener = listener . bind ( thisArg ) ;
1010+ } ,
1011+ getActiveInterpreter : ( ) => ( {
1012+ envPath : 'foo' ,
1013+ path : 'path/to/foo' ,
1014+ } ) ,
1015+ } as unknown ) as IInterpreterService ;
1016+
1017+ watcher = new LanguageServerWatcher (
1018+ ( {
1019+ get : ( ) => {
1020+ /* do nothing */
1021+ } ,
1022+ } as unknown ) as IServiceContainer ,
1023+ { } as ILanguageServerOutputChannel ,
1024+ {
1025+ getSettings : ( ) => ( { languageServer : LanguageServerType . None } ) ,
1026+ } as IConfigurationService ,
1027+ { } as IExperimentService ,
1028+ ( {
1029+ getActiveWorkspaceUri : ( ) => undefined ,
1030+ } as unknown ) as IInterpreterHelper ,
1031+ ( {
1032+ onDidChange : ( ) => {
1033+ /* do nothing */
1034+ } ,
1035+ } as unknown ) as IInterpreterPathService ,
1036+ interpreterService ,
1037+ ( {
1038+ onDidEnvironmentVariablesChange : ( ) => {
1039+ /* do nothing */
1040+ } ,
1041+ } as unknown ) as IEnvironmentVariablesProvider ,
1042+ ( {
1043+ isTrusted : true ,
1044+ getWorkspaceFolder : ( uri : Uri ) => ( { uri } ) ,
1045+ onDidChangeConfiguration : ( ) => {
1046+ /* do nothing */
1047+ } ,
1048+ onDidChangeWorkspaceFolders : ( ) => {
1049+ /* do nothing */
1050+ } ,
1051+ } as unknown ) as IWorkspaceService ,
1052+ ( {
1053+ registerCommand : ( ) => {
1054+ /* do nothing */
1055+ } ,
1056+ } as unknown ) as ICommandManager ,
1057+ { } as IFileSystem ,
1058+ ( {
1059+ getExtension : ( ) => undefined ,
1060+ onDidChange : ( ) => {
1061+ /* do nothing */
1062+ } ,
1063+ } as unknown ) as IExtensions ,
1064+ { } as IApplicationShell ,
1065+ [ ] as Disposable [ ] ,
1066+ ) ;
1067+
1068+ const startLanguageServerSpy = sandbox . spy ( watcher , 'startLanguageServer' ) ;
1069+
1070+ await watcher . startLanguageServer ( LanguageServerType . None ) ;
1071+
1072+ await onDidChangeInfoListener ( info ) ;
1073+
1074+ // Check that startLanguageServer was called once: Only when startLanguageServer() was called above.
1075+ assert . ok ( startLanguageServerSpy . calledOnce ) ;
1076+ } ) ;
1077+
1078+ test ( 'The language server should not be restarted if the interpreter info changed but the env path is undefined' , async ( ) => {
1079+ const info = ( {
1080+ envPath : undefined ,
1081+ path : 'path/to/foo' ,
1082+ } as unknown ) as PythonEnvironment ;
1083+
1084+ let onDidChangeInfoListener : ( event : PythonEnvironment ) => Promise < void > = ( ) => Promise . resolve ( ) ;
1085+
1086+ const interpreterService = ( {
1087+ onDidChangeInterpreterInformation : (
1088+ listener : ( event : PythonEnvironment ) => Promise < void > ,
1089+ thisArg : unknown ,
1090+ ) : void => {
1091+ onDidChangeInfoListener = listener . bind ( thisArg ) ;
1092+ } ,
1093+ getActiveInterpreter : ( ) => ( {
1094+ envPath : 'foo' ,
1095+ path : 'path/to/foo' ,
1096+ } ) ,
1097+ } as unknown ) as IInterpreterService ;
1098+
1099+ watcher = new LanguageServerWatcher (
1100+ ( {
1101+ get : ( ) => {
1102+ /* do nothing */
1103+ } ,
1104+ } as unknown ) as IServiceContainer ,
1105+ { } as ILanguageServerOutputChannel ,
1106+ {
1107+ getSettings : ( ) => ( { languageServer : LanguageServerType . None } ) ,
1108+ } as IConfigurationService ,
1109+ { } as IExperimentService ,
1110+ ( {
1111+ getActiveWorkspaceUri : ( ) => undefined ,
1112+ } as unknown ) as IInterpreterHelper ,
1113+ ( {
1114+ onDidChange : ( ) => {
1115+ /* do nothing */
1116+ } ,
1117+ } as unknown ) as IInterpreterPathService ,
1118+ interpreterService ,
1119+ ( {
1120+ onDidEnvironmentVariablesChange : ( ) => {
1121+ /* do nothing */
1122+ } ,
1123+ } as unknown ) as IEnvironmentVariablesProvider ,
1124+ ( {
1125+ isTrusted : true ,
1126+ getWorkspaceFolder : ( uri : Uri ) => ( { uri } ) ,
1127+ onDidChangeConfiguration : ( ) => {
1128+ /* do nothing */
1129+ } ,
1130+ onDidChangeWorkspaceFolders : ( ) => {
1131+ /* do nothing */
1132+ } ,
1133+ } as unknown ) as IWorkspaceService ,
1134+ ( {
1135+ registerCommand : ( ) => {
1136+ /* do nothing */
1137+ } ,
1138+ } as unknown ) as ICommandManager ,
1139+ { } as IFileSystem ,
1140+ ( {
1141+ getExtension : ( ) => undefined ,
1142+ onDidChange : ( ) => {
1143+ /* do nothing */
1144+ } ,
1145+ } as unknown ) as IExtensions ,
1146+ { } as IApplicationShell ,
1147+ [ ] as Disposable [ ] ,
1148+ ) ;
1149+
1150+ const startLanguageServerSpy = sandbox . spy ( watcher , 'startLanguageServer' ) ;
1151+
1152+ await watcher . startLanguageServer ( LanguageServerType . None ) ;
1153+
1154+ await onDidChangeInfoListener ( info ) ;
1155+
1156+ // Check that startLanguageServer was called once: Only when startLanguageServer() was called above.
1157+ assert . ok ( startLanguageServerSpy . calledOnce ) ;
1158+ } ) ;
9951159} ) ;
0 commit comments