Skip to content

Commit 5f31edd

Browse files
arikonclaude
authored andcommitted
fix: address SonarCloud issues in roles context initialization
- 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>
1 parent be60330 commit 5f31edd

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,10 @@ export async function activate(context: ExtensionContext): Promise<void> {
11251125
}),
11261126
);
11271127
context.subscriptions.push(eeBuilderCommand);
1128+
1129+
// Initialize workspace context for ansible roles (async, at the end of activate
1130+
// to avoid blocking early extension host initialization)
1131+
await lightSpeedManager.setContext();
11281132
}
11291133

11301134
const startClient = async (

src/features/lightspeed/base.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)