@@ -157,6 +157,7 @@ export class TestControllerManager {
157157 private diagnosticCollection = vscode . languages . createDiagnosticCollection ( "robotCode discovery" ) ;
158158 private activeStepDecorationType : vscode . TextEditorDecorationType ;
159159 showEditorRunDecorations = false ;
160+ private readonly profilesCache = new WeakMap < vscode . WorkspaceFolder , RobotCodeProfilesResult > ( ) ;
160161
161162 constructor (
162163 public readonly extensionContext : vscode . ExtensionContext ,
@@ -208,13 +209,16 @@ export class TestControllerManager {
208209 fileWatcher ,
209210 this . activeStepDecorationType ,
210211 this . languageClientsManager . onClientStateChanged ( async ( event ) => {
212+ const folder = vscode . workspace . getWorkspaceFolder ( event . uri ) ;
213+ if ( folder ) {
214+ this . invalidateProfilesCache ( folder ) ;
215+ }
211216 switch ( event . state ) {
212217 case ClientState . Running : {
213218 await this . refresh ( ) ;
214219 break ;
215220 }
216221 case ClientState . Stopped : {
217- const folder = vscode . workspace . getWorkspaceFolder ( event . uri ) ;
218222 if ( folder ) this . removeWorkspaceFolderItems ( folder ) ;
219223
220224 break ;
@@ -446,6 +450,16 @@ export class TestControllerManager {
446450 } ) ;
447451 }
448452
453+ public invalidateProfilesCache ( folder ?: vscode . WorkspaceFolder ) : void {
454+ if ( folder ) {
455+ this . profilesCache . delete ( folder ) ;
456+ } else {
457+ for ( const ws of vscode . workspace . workspaceFolders ?? [ ] ) {
458+ this . profilesCache . delete ( ws ) ;
459+ }
460+ }
461+ }
462+
449463 public async getRobotCodeProfiles (
450464 folder : vscode . WorkspaceFolder ,
451465 profiles ?: string [ ] ,
@@ -456,17 +470,30 @@ export class TestControllerManager {
456470 messages : [ ] ,
457471 } as RobotCodeProfilesResult ;
458472 }
473+
474+ // Use cache only when no specific profiles are requested
475+ if ( profiles === undefined && this . profilesCache . has ( folder ) ) {
476+ return this . profilesCache . get ( folder ) ! ;
477+ }
478+
459479 const config = vscode . workspace . getConfiguration ( CONFIG_SECTION , folder ) ;
460480 const paths = config . get < string [ ] | undefined > ( "robot.paths" , undefined ) ;
461481
462- return ( await this . languageClientsManager . pythonManager . executeRobotCode (
482+ const result = ( await this . languageClientsManager . pythonManager . executeRobotCode (
463483 folder ,
464484 [ ...( paths ?. length ? paths . flatMap ( ( v ) => [ "-dp" , v ] ) : [ "-dp" , "." ] ) , "profiles" , "list" ] ,
465485 profiles ,
466486 "json" ,
467487 true ,
468488 true ,
469489 ) ) as RobotCodeProfilesResult ;
490+
491+ // Cache the result only when no specific profiles were requested
492+ if ( profiles === undefined ) {
493+ this . profilesCache . set ( folder , result ) ;
494+ }
495+
496+ return result ;
470497 }
471498
472499 public async selectConfigurationProfiles ( folder ?: vscode . WorkspaceFolder ) : Promise < void > {
0 commit comments