fix: make roles context initialization async to unblock extension host#2655
fix: make roles context initialization async to unblock extension host#2655arikon wants to merge 3 commits intoansible:mainfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
|
@ssbarnea Could you have a look, please? |
|
Thanks @arikon. This is super cool. |
Replace synchronous glob.sync and fs.*Sync calls in LightSpeedManager startup path with async equivalents. This prevents extension host freeze on large monorepos where recursive workspace scan could take 5+ seconds. Changes: - Convert getCustomRolePaths to use async glob() with maxDepth limit - Convert updateRolesContext/updateRoleContext/readVarFiles to async fs - Fix watchRolesDirectory: return disposables, use async updateRolesContext - Fix onDidDelete: replace broken `in` on array with `.includes()`, remove fs.statSync on deleted path, use live ansibleRolesCache reference - Fix data.ts: replace forEach(async) antipattern with for...of - Add AbortController guard for race conditions in setContext - Add watcher cleanup on resetContext/reInitialize Fixes ansible#2607 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move async setContext() call from constructor to end of activate() - Extract watchRolePaths() to reduce cognitive complexity (20 → ~12) - Invert negated condition for clarity Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
784b2c4 to
5f31edd
Compare
|
note: The failing UI tests pass just fine locally. |
|
This PR will be blocked because of the "Commits must have verified signatures." rule. @arikon could you set-up a SSH key to sign your commit and rebase your commit? |
|
@arikon The only issue that I see is what the quality gate reported coverage of new code under 80% |
Pull request was converted to draft
|
Moved to draft, bring it back from draft only after all CI jobs report green. |
|
@arikon Any chance you can resolve conflicts on this one please? Rebase and squash and we should be ready to merge it. |
Summary
Fixes #2607
The
LightSpeedManagerconstructor synchronously scans the entire workspace viaglob.sync("**/roles", ...)duringactivate(), blocking the extension host for 50+ seconds on large monorepos.This PR converts the entire call chain to async:
getCustomRolePaths—glob.sync→await glob()withmaxDepth: 6limitupdateRolesContext/updateRoleContext/readVarFiles—fs.*Sync→fs.promises.*watchRolesDirectory— async, returnsDisposable[]for proper cleanupLightSpeedManager.setContext— async, fire-and-forget from constructor viavoid this.setContext()data.ts:getRoleYamlFiles— fixforEach(async ...)antipattern →for...ofBug fixes included
watchers.ts:onDidDelete—fs.statSyncon already-deleted path → ENOENT crashwatchers.ts:onDidDelete—dirPath in StandardRolePathsalwaysfalse(inchecks array indices, not values) →.includes()watchers.ts— capturedansibleRolesCachereference becomes stale afterresetContext()→ uselightSpeedManager.ansibleRolesCachedirectlywatchers.ts— watcher leak onreInitialize()→ proper dispose via_watchersarrayAbortControllerinsetContext()