Skip to content

Commit ee759ab

Browse files
Move installOrUpdateThenTryActivate to top level
1 parent a8f67d7 commit ee759ab

1 file changed

Lines changed: 80 additions & 58 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -274,64 +274,32 @@ export async function activate(
274274
// Checking the vscode version should not block extension activation.
275275
void assertVSCodeVersionGreaterThan(MIN_VERSION, ctx);
276276

277-
async function installOrUpdateThenTryActivate(
278-
config: DistributionUpdateConfig,
279-
): Promise<CodeQLExtensionInterface | Record<string, never>> {
280-
await installOrUpdateDistribution(ctx, distributionManager, config);
281-
282-
// Display the warnings even if the extension has already activated.
283-
const distributionResult =
284-
await getDistributionDisplayingDistributionWarnings(distributionManager);
285-
let extensionInterface: CodeQLExtensionInterface | Record<string, never> =
286-
{};
287-
if (
288-
!beganMainExtensionActivation &&
289-
distributionResult.kind !== FindDistributionResultKind.NoDistribution
290-
) {
291-
extensionInterface = await activateWithInstalledDistribution(
277+
ctx.subscriptions.push(
278+
distributionConfigListener.onDidChangeConfiguration(() =>
279+
installOrUpdateThenTryActivate(
292280
ctx,
293281
distributionManager,
294282
distributionConfigListener,
295-
);
296-
} else if (
297-
distributionResult.kind === FindDistributionResultKind.NoDistribution
298-
) {
299-
registerErrorStubs([checkForUpdatesCommand], (command) => async () => {
300-
const installActionName = "Install CodeQL CLI";
301-
const chosenAction = await showAndLogErrorMessage(
302-
`Can't execute ${command}: missing CodeQL CLI.`,
303-
{
304-
items: [installActionName],
305-
},
306-
);
307-
if (chosenAction === installActionName) {
308-
await installOrUpdateThenTryActivate({
309-
isUserInitiated: true,
310-
shouldDisplayMessageWhenNoUpdates: false,
311-
allowAutoUpdating: true,
312-
});
313-
}
314-
});
315-
}
316-
return extensionInterface;
317-
}
318-
319-
ctx.subscriptions.push(
320-
distributionConfigListener.onDidChangeConfiguration(() =>
321-
installOrUpdateThenTryActivate({
322-
isUserInitiated: true,
323-
shouldDisplayMessageWhenNoUpdates: false,
324-
allowAutoUpdating: true,
325-
}),
283+
{
284+
isUserInitiated: true,
285+
shouldDisplayMessageWhenNoUpdates: false,
286+
allowAutoUpdating: true,
287+
},
288+
),
326289
),
327290
);
328291
ctx.subscriptions.push(
329292
commandRunner(checkForUpdatesCommand, () =>
330-
installOrUpdateThenTryActivate({
331-
isUserInitiated: true,
332-
shouldDisplayMessageWhenNoUpdates: true,
333-
allowAutoUpdating: true,
334-
}),
293+
installOrUpdateThenTryActivate(
294+
ctx,
295+
distributionManager,
296+
distributionConfigListener,
297+
{
298+
isUserInitiated: true,
299+
shouldDisplayMessageWhenNoUpdates: true,
300+
allowAutoUpdating: true,
301+
},
302+
),
335303
),
336304
);
337305

@@ -341,14 +309,19 @@ export async function activate(
341309
variantAnalysisViewSerializer,
342310
);
343311

344-
const codeQlExtension = await installOrUpdateThenTryActivate({
345-
isUserInitiated: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
346-
shouldDisplayMessageWhenNoUpdates: false,
312+
const codeQlExtension = await installOrUpdateThenTryActivate(
313+
ctx,
314+
distributionManager,
315+
distributionConfigListener,
316+
{
317+
isUserInitiated: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
318+
shouldDisplayMessageWhenNoUpdates: false,
347319

348-
// only auto update on startup if the user has previously requested an update
349-
// otherwise, ask user to accept the update
350-
allowAutoUpdating: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
351-
});
320+
// only auto update on startup if the user has previously requested an update
321+
// otherwise, ask user to accept the update
322+
allowAutoUpdating: !!ctx.globalState.get(shouldUpdateOnNextActivationKey),
323+
},
324+
);
352325

353326
variantAnalysisViewSerializer.onExtensionLoaded(
354327
codeQlExtension.variantAnalysisManager,
@@ -533,6 +506,55 @@ async function getDistributionDisplayingDistributionWarnings(
533506
return result;
534507
}
535508

509+
async function installOrUpdateThenTryActivate(
510+
ctx: ExtensionContext,
511+
distributionManager: DistributionManager,
512+
distributionConfigListener: DistributionConfigListener,
513+
config: DistributionUpdateConfig,
514+
): Promise<CodeQLExtensionInterface | Record<string, never>> {
515+
await installOrUpdateDistribution(ctx, distributionManager, config);
516+
517+
// Display the warnings even if the extension has already activated.
518+
const distributionResult =
519+
await getDistributionDisplayingDistributionWarnings(distributionManager);
520+
let extensionInterface: CodeQLExtensionInterface | Record<string, never> = {};
521+
if (
522+
!beganMainExtensionActivation &&
523+
distributionResult.kind !== FindDistributionResultKind.NoDistribution
524+
) {
525+
extensionInterface = await activateWithInstalledDistribution(
526+
ctx,
527+
distributionManager,
528+
distributionConfigListener,
529+
);
530+
} else if (
531+
distributionResult.kind === FindDistributionResultKind.NoDistribution
532+
) {
533+
registerErrorStubs([checkForUpdatesCommand], (command) => async () => {
534+
const installActionName = "Install CodeQL CLI";
535+
const chosenAction = await showAndLogErrorMessage(
536+
`Can't execute ${command}: missing CodeQL CLI.`,
537+
{
538+
items: [installActionName],
539+
},
540+
);
541+
if (chosenAction === installActionName) {
542+
await installOrUpdateThenTryActivate(
543+
ctx,
544+
distributionManager,
545+
distributionConfigListener,
546+
{
547+
isUserInitiated: true,
548+
shouldDisplayMessageWhenNoUpdates: false,
549+
allowAutoUpdating: true,
550+
},
551+
);
552+
}
553+
});
554+
}
555+
return extensionInterface;
556+
}
557+
536558
const PACK_GLOBS = [
537559
"**/codeql-pack.yml",
538560
"**/qlpack.yml",

0 commit comments

Comments
 (0)