@@ -86,14 +86,16 @@ interface DiscoverInfoResult {
8686 system_version ?: string ;
8787 [ key : string ] : string | undefined ;
8888}
89+
8990export class LanguageClientsManager {
9091 private clientsMutex = new Mutex ( ) ;
92+ private _pythonValidPythonAndRobotEnvMutex = new Mutex ( ) ;
9193
9294 public readonly clients : Map < string , LanguageClient > = new Map ( ) ;
9395 public readonly outputChannels : Map < string , vscode . OutputChannel > = new Map ( ) ;
9496
9597 private _disposables : vscode . Disposable ;
96- private _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
98+ public _pythonValidPythonAndRobotEnv = new WeakMap < vscode . WorkspaceFolder , boolean > ( ) ;
9799 private _workspaceFolderDiscoverInfo = new WeakMap < vscode . WorkspaceFolder , DiscoverInfoResult > ( ) ;
98100
99101 private readonly _onClientStateChangedEmitter = new vscode . EventEmitter < ClientStateChangedEvent > ( ) ;
@@ -236,64 +238,84 @@ export class LanguageClientsManager {
236238 } ) ;
237239 }
238240
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+ }
243249
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+ }
246260
247- if ( ! pythonCommand ) {
248- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
261+ return false ;
262+ }
249263
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+ }
255273
256- return undefined ;
257- }
274+ return false ;
275+ }
258276
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 ) ;
261280
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+ }
267288
268- return undefined ;
269- }
289+ return false ;
290+ }
270291
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 ) ;
274294
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+ }
280302
281- return undefined ;
282- }
303+ return false ;
304+ }
283305
284- if ( robotCheck === false ) {
285- this . _pythonValidPythonAndRobotEnv . set ( folder , false ) ;
306+ this . _pythonValidPythonAndRobotEnv . set ( folder , true ) ;
307+ return true ;
308+ } ) ;
309+ }
286310
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 ) ;
292313
293- return undefined ;
294- }
314+ const envOk = await this . isValidRobotEnvironmentInFolder ( folder , true ) ;
315+ if ( envOk === false ) return undefined ;
295316
296- this . _pythonValidPythonAndRobotEnv . set ( folder , true ) ;
317+ const pythonCommand = this . pythonManager . getPythonCommand ( folder ) ;
318+ if ( ! pythonCommand ) return undefined ;
297319
298320 const robotCodeExtraArgs = config . get < string [ ] > ( "languageServer.extraArgs" , [ ] ) ;
299321
@@ -714,7 +736,7 @@ export class LanguageClientsManager {
714736 try {
715737 const folder = vscode . workspace . getWorkspaceFolder ( editor . document . uri ) ;
716738 if ( folder ) {
717- if ( ! this . _workspaceFolderDiscoverInfo . has ( folder ) ) {
739+ if ( ! this . _workspaceFolderDiscoverInfo . has ( folder ) && ( await this . isValidRobotEnvironmentInFolder ( folder ) ) ) {
718740 this . _workspaceFolderDiscoverInfo . set (
719741 folder ,
720742 ( await this . pythonManager . executeRobotCode ( folder , [ "discover" , "info" ] ) ) as DiscoverInfoResult ,
0 commit comments