@@ -86,14 +86,16 @@ interface DiscoverInfoResult {
86
86
system_version ?: string ;
87
87
[ key : string ] : string | undefined ;
88
88
}
89
+
89
90
export class LanguageClientsManager {
90
91
private clientsMutex = new Mutex ( ) ;
92
+ private _pythonValidPythonAndRobotEnvMutex = new Mutex ( ) ;
91
93
92
94
public readonly clients : Map < string , LanguageClient > = new Map ( ) ;
93
95
public readonly outputChannels : Map < string , vscode . OutputChannel > = new Map ( ) ;
94
96
95
97
private _disposables : vscode . Disposable ;
96
- private _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
98
+ public _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
97
99
private _workspaceFolderDiscoverInfo = new WeakMap < vscode . WorkspaceFolder , DiscoverInfoResult > ( ) ;
98
100
99
101
private readonly _onClientStateChangedEmitter = new vscode . EventEmitter < ClientStateChangedEvent > ( ) ;
@@ -236,64 +238,84 @@ export class LanguageClientsManager {
236
238
} ) ;
237
239
}
238
240
239
- private async getServerOptions ( folder : vscode . WorkspaceFolder , mode : string ) : Promise < ServerOptions | undefined > {
240
- const config = vscode . workspace . getConfiguration ( CONFIG_SECTION , folder ) ;
241
-
242
- const pythonCommand = this . pythonManager . getPythonCommand ( folder ) ;
241
+ public async isValidRobotEnvironmentInFolder (
242
+ folder : vscode . WorkspaceFolder ,
243
+ showDialogs ?: boolean ,
244
+ ) : Promise < boolean > {
245
+ return await this . _pythonValidPythonAndRobotEnvMutex . dispatch ( ( ) => {
246
+ if ( this . _pythonValidPythonAndRobotEnv . has ( folder ) ) {
247
+ return this . _pythonValidPythonAndRobotEnv . get ( folder ) ?? false ;
248
+ }
243
249
244
- const envOk = this . _pythonValidPythonAndRobotEnv . get ( folder ) ;
245
- if ( envOk === false ) return undefined ;
250
+ const pythonCommand = this . pythonManager . getPythonCommand ( folder ) ;
251
+ if ( ! pythonCommand ) {
252
+ this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
253
+ if ( showDialogs ) {
254
+ this . showErrorWithSelectPythonInterpreter (
255
+ `Can't find a valid python executable for workspace folder '${ folder . name } '. ` +
256
+ "Check if python and the python extension is installed." ,
257
+ folder ,
258
+ ) ;
259
+ }
246
260
247
- if ( ! pythonCommand ) {
248
- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
261
+ return false ;
262
+ }
249
263
250
- this . showErrorWithSelectPythonInterpreter (
251
- `Can't find a valid python executable for workspace folder '${ folder . name } '. ` +
252
- "Check if python and the python extension is installed." ,
253
- folder ,
254
- ) ;
264
+ if ( ! this . pythonManager . checkPythonVersion ( pythonCommand ) ) {
265
+ this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
266
+ if ( showDialogs ) {
267
+ this . showErrorWithSelectPythonInterpreter (
268
+ `Invalid python version for workspace folder '${ folder . name } '. Only python version >= 3.8 supported. ` +
269
+ "Please update to a newer python version or select a valid python environment." ,
270
+ folder ,
271
+ ) ;
272
+ }
255
273
256
- return undefined ;
257
- }
274
+ return false ;
275
+ }
258
276
259
- if ( ! this . pythonManager . checkPythonVersion ( pythonCommand ) ) {
260
- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
277
+ const robotCheck = this . pythonManager . checkRobotVersion ( pythonCommand ) ;
278
+ if ( robotCheck === undefined ) {
279
+ this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
261
280
262
- this . showErrorWithSelectPythonInterpreter (
263
- `Invalid python version for workspace folder '${ folder . name } '. Only python version >= 3.8 supported. ` +
264
- "Please update to a newer python version or select a valid python environment." ,
265
- folder ,
266
- ) ;
281
+ if ( showDialogs ) {
282
+ this . showErrorWithSelectPythonInterpreter (
283
+ `Robot Framework package not found in workspace folder '${ folder . name } '. ` +
284
+ "Please install Robot Framework >= version 4.1 to the current python environment or select a valid python environment." ,
285
+ folder ,
286
+ ) ;
287
+ }
267
288
268
- return undefined ;
269
- }
289
+ return false ;
290
+ }
270
291
271
- const robotCheck = this . pythonManager . checkRobotVersion ( pythonCommand ) ;
272
- if ( robotCheck === undefined ) {
273
- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
292
+ if ( robotCheck === false ) {
293
+ this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
274
294
275
- this . showErrorWithSelectPythonInterpreter (
276
- `Robot Framework package not found in workspace folder '${ folder . name } '. ` +
277
- "Please install Robot Framework >= Version 4.0 to the current python environment or select a valid python environment." ,
278
- folder ,
279
- ) ;
295
+ if ( showDialogs ) {
296
+ this . showErrorWithSelectPythonInterpreter (
297
+ `Robot Framework version in workspace folder '${ folder . name } ' not supported. Only Robot Framework version >= 4.1 supported. ` +
298
+ "Please install or update to Robot Framework >= version 4.1 to the current python environment or select a valid python environment." ,
299
+ folder ,
300
+ ) ;
301
+ }
280
302
281
- return undefined ;
282
- }
303
+ return false ;
304
+ }
283
305
284
- if ( robotCheck === false ) {
285
- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
306
+ this . _pythonValidPythonAndRobotEnv . set ( folder , true ) ;
307
+ return true ;
308
+ } ) ;
309
+ }
286
310
287
- this . showErrorWithSelectPythonInterpreter (
288
- `Robot Framework version in workspace folder '${ folder . name } ' not supported. Only Robot Framework version >= 4.0.0 supported. ` +
289
- "Please install or update Robot Framework >= Version 4.0 to the current python environment or select a valid python environment." ,
290
- folder ,
291
- ) ;
311
+ private async getServerOptions ( folder : vscode . WorkspaceFolder , mode : string ) : Promise < ServerOptions | undefined > {
312
+ const config = vscode . workspace . getConfiguration ( CONFIG_SECTION , folder ) ;
292
313
293
- return undefined ;
294
- }
314
+ const envOk = await this . isValidRobotEnvironmentInFolder ( folder , true ) ;
315
+ if ( envOk === false ) return undefined ;
295
316
296
- this . _pythonValidPythonAndRobotEnv . set ( folder , true ) ;
317
+ const pythonCommand = this . pythonManager . getPythonCommand ( folder ) ;
318
+ if ( ! pythonCommand ) return undefined ;
297
319
298
320
const robotCodeExtraArgs = config . get < string [ ] > ( "languageServer.extraArgs" , [ ] ) ;
299
321
@@ -714,7 +736,7 @@ export class LanguageClientsManager {
714
736
try {
715
737
const folder = vscode . workspace . getWorkspaceFolder ( editor . document . uri ) ;
716
738
if ( folder ) {
717
- if ( ! this . _workspaceFolderDiscoverInfo . has ( folder ) ) {
739
+ if ( ! this . _workspaceFolderDiscoverInfo . has ( folder ) && ( await this . isValidRobotEnvironmentInFolder ( folder ) ) ) {
718
740
this . _workspaceFolderDiscoverInfo . set (
719
741
folder ,
720
742
( await this . pythonManager . executeRobotCode ( folder , [ "discover" , "info" ] ) ) as DiscoverInfoResult ,
0 commit comments