@@ -114,9 +114,6 @@ export class LightSpeedManager {
114114 // Generative AI features are now in the LLM Provider Settings panel
115115 this . lightspeedExplorerProvider = undefined ;
116116
117- // create workspace context for ansible roles (async, non-blocking)
118- void this . setContext ( ) ;
119-
120117 // set custom when clause for controlling visibility of views
121118 this . setCustomWhenClauseContext ( ) ;
122119 }
@@ -153,7 +150,7 @@ export class LightSpeedManager {
153150 this . _contextInitAbort = null ;
154151 }
155152
156- private async setContext ( ) : Promise < void > {
153+ public async setContext ( ) : Promise < void > {
157154 this . _contextInitAbort ?. abort ( ) ;
158155 const abort = new AbortController ( ) ;
159156 this . _contextInitAbort = abort ;
@@ -166,31 +163,41 @@ export class LightSpeedManager {
166163 if ( abort . signal . aborted ) return ;
167164 const workSpaceRoot = workspaceFolder . uri . fsPath ;
168165 const rolesPath = await getCustomRolePaths ( workSpaceRoot ) ;
169- for ( const rolePath of rolesPath ) {
170- if ( abort . signal . aborted ) return ;
171- const disposables = await watchRolesDirectory (
172- this ,
173- rolePath ,
174- workSpaceRoot ,
175- ) ;
176- newWatchers . push ( ...disposables ) ;
177- }
166+ await this . watchRolePaths (
167+ rolesPath ,
168+ newWatchers ,
169+ abort . signal ,
170+ workSpaceRoot ,
171+ ) ;
178172 }
179173 }
180174
181175 const commonRolesPath = getCommonRoles ( ) || [ ] ;
182- for ( const rolePath of commonRolesPath ) {
183- if ( abort . signal . aborted ) return ;
184- const disposables = await watchRolesDirectory ( this , rolePath ) ;
185- newWatchers . push ( ...disposables ) ;
186- }
176+ await this . watchRolePaths ( commonRolesPath , newWatchers , abort . signal ) ;
187177
188- if ( ! abort . signal . aborted ) {
189- this . _watchers = newWatchers ;
190- } else {
178+ if ( abort . signal . aborted ) {
191179 for ( const d of newWatchers ) {
192180 d . dispose ( ) ;
193181 }
182+ } else {
183+ this . _watchers = newWatchers ;
184+ }
185+ }
186+
187+ private async watchRolePaths (
188+ rolePaths : string [ ] ,
189+ watchers : vscode . Disposable [ ] ,
190+ signal : AbortSignal ,
191+ workSpaceRoot ?: string ,
192+ ) : Promise < void > {
193+ for ( const rolePath of rolePaths ) {
194+ if ( signal . aborted ) return ;
195+ const disposables = await watchRolesDirectory (
196+ this ,
197+ rolePath ,
198+ workSpaceRoot ,
199+ ) ;
200+ watchers . push ( ...disposables ) ;
194201 }
195202 }
196203
0 commit comments