Skip to content

Commit 118be4a

Browse files
Move installOrUpdateDistribution to top level
1 parent 8d3ae78 commit 118be4a

1 file changed

Lines changed: 60 additions & 60 deletions

File tree

extensions/ql-vscode/src/extension.ts

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

277-
async function installOrUpdateDistribution(
278-
config: DistributionUpdateConfig,
279-
): Promise<void> {
280-
if (isInstallingOrUpdatingDistribution) {
281-
throw new Error("Already installing or updating CodeQL CLI");
282-
}
283-
isInstallingOrUpdatingDistribution = true;
284-
const codeQlInstalled =
285-
(await distributionManager.getCodeQlPathWithoutVersionCheck()) !==
286-
undefined;
287-
const willUpdateCodeQl = ctx.globalState.get(
288-
shouldUpdateOnNextActivationKey,
289-
);
290-
const messageText = willUpdateCodeQl
291-
? "Updating CodeQL CLI"
292-
: codeQlInstalled
293-
? "Checking for updates to CodeQL CLI"
294-
: "Installing CodeQL CLI";
295-
296-
try {
297-
await installOrUpdateDistributionWithProgressTitle(
298-
ctx,
299-
distributionManager,
300-
messageText,
301-
config,
302-
);
303-
} catch (e) {
304-
// Don't rethrow the exception, because if the config is changed, we want to be able to retry installing
305-
// or updating the distribution.
306-
const alertFunction =
307-
codeQlInstalled && !config.isUserInitiated
308-
? showAndLogWarningMessage
309-
: showAndLogErrorMessage;
310-
const taskDescription = `${
311-
willUpdateCodeQl
312-
? "update"
313-
: codeQlInstalled
314-
? "check for updates to"
315-
: "install"
316-
} CodeQL CLI`;
317-
318-
if (e instanceof GithubRateLimitedError) {
319-
void alertFunction(
320-
`Rate limited while trying to ${taskDescription}. Please try again after ` +
321-
`your rate limit window resets at ${e.rateLimitResetDate.toLocaleString(
322-
env.language,
323-
)}.`,
324-
);
325-
} else if (e instanceof GithubApiError) {
326-
void alertFunction(
327-
`Encountered GitHub API error while trying to ${taskDescription}. ${e}`,
328-
);
329-
}
330-
void alertFunction(`Unable to ${taskDescription}. ${e}`);
331-
} finally {
332-
isInstallingOrUpdatingDistribution = false;
333-
}
334-
}
335-
336277
async function getDistributionDisplayingDistributionWarnings(): Promise<FindDistributionResult> {
337278
const result = await distributionManager.getDistribution();
338279
switch (result.kind) {
@@ -380,7 +321,7 @@ export async function activate(
380321
async function installOrUpdateThenTryActivate(
381322
config: DistributionUpdateConfig,
382323
): Promise<CodeQLExtensionInterface | Record<string, never>> {
383-
await installOrUpdateDistribution(config);
324+
await installOrUpdateDistribution(ctx, distributionManager, config);
384325

385326
// Display the warnings even if the extension has already activated.
386327
const distributionResult =
@@ -531,6 +472,65 @@ async function installOrUpdateDistributionWithProgressTitle(
531472
}
532473
}
533474

475+
async function installOrUpdateDistribution(
476+
ctx: ExtensionContext,
477+
distributionManager: DistributionManager,
478+
config: DistributionUpdateConfig,
479+
): Promise<void> {
480+
if (isInstallingOrUpdatingDistribution) {
481+
throw new Error("Already installing or updating CodeQL CLI");
482+
}
483+
isInstallingOrUpdatingDistribution = true;
484+
const codeQlInstalled =
485+
(await distributionManager.getCodeQlPathWithoutVersionCheck()) !==
486+
undefined;
487+
const willUpdateCodeQl = ctx.globalState.get(shouldUpdateOnNextActivationKey);
488+
const messageText = willUpdateCodeQl
489+
? "Updating CodeQL CLI"
490+
: codeQlInstalled
491+
? "Checking for updates to CodeQL CLI"
492+
: "Installing CodeQL CLI";
493+
494+
try {
495+
await installOrUpdateDistributionWithProgressTitle(
496+
ctx,
497+
distributionManager,
498+
messageText,
499+
config,
500+
);
501+
} catch (e) {
502+
// Don't rethrow the exception, because if the config is changed, we want to be able to retry installing
503+
// or updating the distribution.
504+
const alertFunction =
505+
codeQlInstalled && !config.isUserInitiated
506+
? showAndLogWarningMessage
507+
: showAndLogErrorMessage;
508+
const taskDescription = `${
509+
willUpdateCodeQl
510+
? "update"
511+
: codeQlInstalled
512+
? "check for updates to"
513+
: "install"
514+
} CodeQL CLI`;
515+
516+
if (e instanceof GithubRateLimitedError) {
517+
void alertFunction(
518+
`Rate limited while trying to ${taskDescription}. Please try again after ` +
519+
`your rate limit window resets at ${e.rateLimitResetDate.toLocaleString(
520+
env.language,
521+
)}.`,
522+
);
523+
} else if (e instanceof GithubApiError) {
524+
void alertFunction(
525+
`Encountered GitHub API error while trying to ${taskDescription}. ${e}`,
526+
);
527+
}
528+
void alertFunction(`Unable to ${taskDescription}. ${e}`);
529+
} finally {
530+
isInstallingOrUpdatingDistribution = false;
531+
}
532+
}
533+
534534
const PACK_GLOBS = [
535535
"**/codeql-pack.yml",
536536
"**/qlpack.yml",

0 commit comments

Comments
 (0)