From 018d719de395f5255b20784eafd7736c52ac5551 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 9 Dec 2024 15:02:34 -0500 Subject: [PATCH 01/14] run branch check on PRs only --- .github/workflows/node.js.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index d42b6ef76ee..7dbd9730049 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,6 +33,7 @@ jobs: with: node-version: '20' - name: Check Branch title + if: ${{ github.event_name == 'pull_request'}} env: BRANCH_NAME: ${{ github.head_ref }} run: | From d03a2dad47fb665ec55b902b2515f1ac526de812 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 9 Dec 2024 15:06:06 -0500 Subject: [PATCH 02/14] use event branch name --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 7dbd9730049..4d2ace1080c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -35,7 +35,7 @@ jobs: - name: Check Branch title if: ${{ github.event_name == 'pull_request'}} env: - BRANCH_NAME: ${{ github.head_ref }} + BRANCH_NAME: ${{ github.event.pull_request.head.ref }} run: | node "$GITHUB_WORKSPACE/.github/workflows/lintbranch.js" run "$BRANCH_NAME" - name: Check PR title From 4fb8e66da03c6efb523ab523f8c3d9a769abc622 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 9 Dec 2024 15:16:32 -0500 Subject: [PATCH 03/14] change wording --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4d2ace1080c..6d057d0ddf4 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -32,7 +32,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: '20' - - name: Check Branch title + - name: Validate Branch name if: ${{ github.event_name == 'pull_request'}} env: BRANCH_NAME: ${{ github.event.pull_request.head.ref }} From cdecab61aa146bef8816b24eb0db44699855797e Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 9 Dec 2024 15:21:27 -0500 Subject: [PATCH 04/14] add extra check --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 6d057d0ddf4..86e6db52651 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,7 +33,7 @@ jobs: with: node-version: '20' - name: Validate Branch name - if: ${{ github.event_name == 'pull_request'}} + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != ""}} env: BRANCH_NAME: ${{ github.event.pull_request.head.ref }} run: | From f2900e5c570b16a649086f0cc43ca4e2d33ec870 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 9 Dec 2024 15:27:37 -0500 Subject: [PATCH 05/14] switch to single quotes --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 86e6db52651..a7541f39b9c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,7 +33,7 @@ jobs: with: node-version: '20' - name: Validate Branch name - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != ""}} + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != ''}} env: BRANCH_NAME: ${{ github.event.pull_request.head.ref }} run: | From e16fe17422f026c5082625efcec57492eb2209ad Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 13 Dec 2024 16:24:47 -0500 Subject: [PATCH 06/14] factor out to general isEnabled function --- packages/core/src/shared/settings.ts | 60 ++++++++++++++-------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index a34ba2f8d2d..f3fe77e7550 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -600,7 +600,7 @@ export function fromExtensionManifest { - try { - return !this._getOrThrow(promptName, false) - } catch (e) { - this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) - await this.reset() - - return true - } + public isPromptEnabled(promptName: toolkitPromptName) { + return isEnabled(this, promptName) } public async disablePrompt(promptName: toolkitPromptName): Promise { - if (await this.isPromptEnabled(promptName)) { + if (this.isPromptEnabled(promptName)) { await this.update(promptName, true) } } @@ -660,19 +653,12 @@ export class AmazonQPromptSettings ) implements PromptSettings { - public async isPromptEnabled(promptName: amazonQPromptName): Promise { - try { - return !this._getOrThrow(promptName, false) - } catch (e) { - this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) - await this.reset() - - return true - } + public isPromptEnabled(promptName: amazonQPromptName): boolean { + return isEnabled(this, promptName) } public async disablePrompt(promptName: amazonQPromptName): Promise { - if (await this.isPromptEnabled(promptName)) { + if (this.isPromptEnabled(promptName)) { await this.update(promptName, true) } } @@ -692,7 +678,7 @@ export class AmazonQPromptSettings type AllPromptNames = amazonQPromptName | toolkitPromptName export interface PromptSettings { - isPromptEnabled(promptName: AllPromptNames): Promise + isPromptEnabled(promptName: AllPromptNames): boolean disablePrompt(promptName: AllPromptNames): Promise } @@ -708,7 +694,7 @@ type ExperimentName = keyof typeof experiments * ### Usage: * ``` * function myExperimentalFeature(): void { - * if (!(await settings.isExperimentEnabled('myExperimentalFeature'))) { + * if (!(settings.isExperimentEnabled('myExperimentalFeature'))) { * return * } * @@ -727,14 +713,7 @@ export class Experiments extends Settings.define( toRecord(keys(experiments), () => Boolean) ) { public isExperimentEnabled(name: ExperimentName): boolean { - try { - return this._getOrThrow(name, false) - } catch (error) { - this._log(`experiment check for ${name} failed: %s`, error) - this.reset().catch((e) => getLogger().error(`failed to reset experiment settings: %O`, e)) - - return false - } + return isEnabled(this, name) } static #instance: Experiments @@ -949,3 +928,22 @@ export async function openSettings(prefix: string): Promise { export async function openSettingsId(key: K): Promise { await vscode.commands.executeCommand('workbench.action.openSettings', `@id:${key}`) } + +function isEnabled< + S extends { + _getOrThrow(key: P & string, defaultValue: boolean): boolean + _log(message: string, ...args: any[]): void + update(key: P & string, value: boolean): Promise + reset(): Promise + }, + P extends AllPromptNames | ExperimentName, +>(settings: S, promptName: P) { + try { + return !settings._getOrThrow(promptName, false) + } catch (e) { + settings._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) + settings.reset().catch((e) => getLogger().error(`failed to reset prompt settings: %O`, (e as Error).message)) + + return true + } +} From 4498a73d4ee4c84c27702040e173fdf7a35a34af Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 13 Dec 2024 16:40:36 -0500 Subject: [PATCH 07/14] avoid using same function for experiment --- packages/core/src/shared/settings.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index f3fe77e7550..c8b249299ec 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -628,7 +628,7 @@ export class ToolkitPromptSettings implements PromptSettings { public isPromptEnabled(promptName: toolkitPromptName) { - return isEnabled(this, promptName) + return isPromptEnabled(this, promptName) } public async disablePrompt(promptName: toolkitPromptName): Promise { @@ -654,7 +654,7 @@ export class AmazonQPromptSettings implements PromptSettings { public isPromptEnabled(promptName: amazonQPromptName): boolean { - return isEnabled(this, promptName) + return isPromptEnabled(this, promptName) } public async disablePrompt(promptName: amazonQPromptName): Promise { @@ -694,7 +694,7 @@ type ExperimentName = keyof typeof experiments * ### Usage: * ``` * function myExperimentalFeature(): void { - * if (!(settings.isExperimentEnabled('myExperimentalFeature'))) { + * if (!( settings.isExperimentEnabled('myExperimentalFeature'))) { * return * } * @@ -713,7 +713,14 @@ export class Experiments extends Settings.define( toRecord(keys(experiments), () => Boolean) ) { public isExperimentEnabled(name: ExperimentName): boolean { - return isEnabled(this, name) + try { + return this._getOrThrow(name, false) + } catch (error) { + this._log(`experiment check for ${name} failed: %s`, error) + this.reset().catch((e) => getLogger().error(`failed to reset experiment settings: %O`, e)) + + return false + } } static #instance: Experiments @@ -929,14 +936,14 @@ export async function openSettingsId(key: K): Pro await vscode.commands.executeCommand('workbench.action.openSettings', `@id:${key}`) } -function isEnabled< +function isPromptEnabled< S extends { _getOrThrow(key: P & string, defaultValue: boolean): boolean _log(message: string, ...args: any[]): void update(key: P & string, value: boolean): Promise reset(): Promise - }, - P extends AllPromptNames | ExperimentName, + } & PromptSettings, + P extends AllPromptNames, >(settings: S, promptName: P) { try { return !settings._getOrThrow(promptName, false) From e9b39f2c6028358a3b1ef00e07232596e499dc1b Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 13 Dec 2024 17:53:57 -0500 Subject: [PATCH 08/14] factor out other method --- packages/core/src/shared/settings.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index c8b249299ec..fc32470b51c 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -632,9 +632,7 @@ export class ToolkitPromptSettings } public async disablePrompt(promptName: toolkitPromptName): Promise { - if (this.isPromptEnabled(promptName)) { - await this.update(promptName, true) - } + return await disablePrompt(this, promptName) } static #instance: ToolkitPromptSettings @@ -658,9 +656,7 @@ export class AmazonQPromptSettings } public async disablePrompt(promptName: amazonQPromptName): Promise { - if (this.isPromptEnabled(promptName)) { - await this.update(promptName, true) - } + return await disablePrompt(this, promptName) } static #instance: AmazonQPromptSettings @@ -954,3 +950,12 @@ function isPromptEnabled< return true } } + +async function disablePrompt< + S extends { update(key: P & string, value: boolean): Promise } & PromptSettings, + P extends AllPromptNames, +>(settings: S, promptName: P) { + if (settings.isPromptEnabled(promptName)) { + await settings.update(promptName, true) + } +} From df97e33e51f0da2d6a3dcc223930a85f41981939 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 13 Dec 2024 17:55:38 -0500 Subject: [PATCH 09/14] move code to be adjacent --- packages/core/src/shared/settings.ts | 56 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index fc32470b51c..24849e71be8 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -666,6 +666,34 @@ export class AmazonQPromptSettings } } +function isPromptEnabled< + S extends { + _getOrThrow(key: P & string, defaultValue: boolean): boolean + _log(message: string, ...args: any[]): void + update(key: P & string, value: boolean): Promise + reset(): Promise + } & PromptSettings, + P extends AllPromptNames, +>(settings: S, promptName: P) { + try { + return !settings._getOrThrow(promptName, false) + } catch (e) { + settings._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) + settings.reset().catch((e) => getLogger().error(`failed to reset prompt settings: %O`, (e as Error).message)) + + return true + } +} + +async function disablePrompt< + S extends { update(key: P & string, value: boolean): Promise } & PromptSettings, + P extends AllPromptNames, +>(settings: S, promptName: P) { + if (settings.isPromptEnabled(promptName)) { + await settings.update(promptName, true) + } +} + /** * Use cautiously as this is misleading. Ideally we create a type * which is the intersection of the types (only the values that occur @@ -931,31 +959,3 @@ export async function openSettings(prefix: string): Promise { export async function openSettingsId(key: K): Promise { await vscode.commands.executeCommand('workbench.action.openSettings', `@id:${key}`) } - -function isPromptEnabled< - S extends { - _getOrThrow(key: P & string, defaultValue: boolean): boolean - _log(message: string, ...args: any[]): void - update(key: P & string, value: boolean): Promise - reset(): Promise - } & PromptSettings, - P extends AllPromptNames, ->(settings: S, promptName: P) { - try { - return !settings._getOrThrow(promptName, false) - } catch (e) { - settings._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) - settings.reset().catch((e) => getLogger().error(`failed to reset prompt settings: %O`, (e as Error).message)) - - return true - } -} - -async function disablePrompt< - S extends { update(key: P & string, value: boolean): Promise } & PromptSettings, - P extends AllPromptNames, ->(settings: S, promptName: P) { - if (settings.isPromptEnabled(promptName)) { - await settings.update(promptName, true) - } -} From ea221220546a44d98f1f0f6bc07512decfa87361 Mon Sep 17 00:00:00 2001 From: hkobew Date: Fri, 13 Dec 2024 18:12:27 -0500 Subject: [PATCH 10/14] generate class based on prompt --- packages/core/src/shared/settings.ts | 98 +++++++++------------------- 1 file changed, 32 insertions(+), 66 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 24849e71be8..75afc03fa48 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -619,78 +619,44 @@ export function fromExtensionManifest Boolean) - ) - implements PromptSettings -{ - public isPromptEnabled(promptName: toolkitPromptName) { - return isPromptEnabled(this, promptName) - } - - public async disablePrompt(promptName: toolkitPromptName): Promise { - return await disablePrompt(this, promptName) - } - - static #instance: ToolkitPromptSettings - - public static get instance() { - return (this.#instance ??= new this()) - } -} +export const ToolkitPromptSettings = getPromptSettings('aws.suppressPrompts', toolkitPrompts) export const amazonQPrompts = settingsProps['amazonQ.suppressPrompts'] -type amazonQPromptName = keyof typeof amazonQPrompts -export class AmazonQPromptSettings - extends Settings.define( - 'amazonQ.suppressPrompts', - toRecord(keys(amazonQPrompts), () => Boolean) - ) - implements PromptSettings -{ - public isPromptEnabled(promptName: amazonQPromptName): boolean { - return isPromptEnabled(this, promptName) - } +export const AmazonQPromptSettings = getPromptSettings('amazonQ.suppressPrompts', amazonQPrompts) - public async disablePrompt(promptName: amazonQPromptName): Promise { - return await disablePrompt(this, promptName) - } +function getPromptSettings

( + promptsKey: P, + prompts: (typeof settingsProps)[keyof typeof settingsProps] +) { + type promptName = keyof typeof prompts + return class AnonymousPromptSettings extends Settings.define( + promptsKey, + toRecord(keys(prompts), () => Boolean) + ) { + public isPromptEnabled(promptName: promptName) { + try { + return !this._getOrThrow(promptName, false as never) + } catch (e) { + this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) + this.reset().catch((e) => + getLogger().error(`failed to reset prompt settings: %O`, (e as Error).message) + ) - static #instance: AmazonQPromptSettings + return true + } + } - public static get instance() { - return (this.#instance ??= new this()) - } -} + public async disablePrompt(promptName: promptName) { + if (this.isPromptEnabled(promptName)) { + await this.update(promptName, true as never) + } + } -function isPromptEnabled< - S extends { - _getOrThrow(key: P & string, defaultValue: boolean): boolean - _log(message: string, ...args: any[]): void - update(key: P & string, value: boolean): Promise - reset(): Promise - } & PromptSettings, - P extends AllPromptNames, ->(settings: S, promptName: P) { - try { - return !settings._getOrThrow(promptName, false) - } catch (e) { - settings._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) - settings.reset().catch((e) => getLogger().error(`failed to reset prompt settings: %O`, (e as Error).message)) - - return true - } -} + static #instance: AnonymousPromptSettings -async function disablePrompt< - S extends { update(key: P & string, value: boolean): Promise } & PromptSettings, - P extends AllPromptNames, ->(settings: S, promptName: P) { - if (settings.isPromptEnabled(promptName)) { - await settings.update(promptName, true) + public static get instance() { + return (this.#instance ??= new this()) + } } } @@ -699,7 +665,7 @@ async function disablePrompt< * which is the intersection of the types (only the values that occur * in each are selected), but idk how to do that. */ -type AllPromptNames = amazonQPromptName | toolkitPromptName +type AllPromptNames = keyof typeof toolkitPrompts | keyof typeof amazonQPrompts export interface PromptSettings { isPromptEnabled(promptName: AllPromptNames): boolean From 71fc1d962008b6e628de75e0be4e772cee7ab871 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 16 Dec 2024 10:11:34 -0500 Subject: [PATCH 11/14] fix type problem --- packages/core/src/shared/settings.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 75afc03fa48..597954e61cd 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -619,23 +619,22 @@ export function fromExtensionManifest( - promptsKey: P, - prompts: (typeof settingsProps)[keyof typeof settingsProps] -) { +function getPromptSettings(promptsKey: promptSettingsKey) { + const prompts = settingsProps[promptsKey] type promptName = keyof typeof prompts return class AnonymousPromptSettings extends Settings.define( promptsKey, toRecord(keys(prompts), () => Boolean) ) { - public isPromptEnabled(promptName: promptName) { + public isPromptEnabled(promptName: promptName & string) { try { - return !this._getOrThrow(promptName, false as never) + return !this._getOrThrow(promptName, false) } catch (e) { this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) this.reset().catch((e) => @@ -646,9 +645,9 @@ function getPromptSettings

Date: Mon, 16 Dec 2024 10:26:45 -0500 Subject: [PATCH 12/14] export type as well as value --- packages/core/src/shared/settings.ts | 14 ++++++++------ packages/core/src/test/shared/settings.test.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 597954e61cd..54642697a7a 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -620,21 +620,23 @@ export function fromExtensionManifest export const amazonQPrompts = settingsProps['amazonQ.suppressPrompts'] export const AmazonQPromptSettings = getPromptSettings('amazonQ.suppressPrompts') +export type AmazonQPromptSettings = InstanceType type promptSettingsKey = 'amazonQ.suppressPrompts' | 'aws.suppressPrompts' -function getPromptSettings(promptsKey: promptSettingsKey) { +function getPromptSettings

(promptsKey: P) { const prompts = settingsProps[promptsKey] - type promptName = keyof typeof prompts + type promptName = keyof typeof prompts & string return class AnonymousPromptSettings extends Settings.define( promptsKey, toRecord(keys(prompts), () => Boolean) ) { - public isPromptEnabled(promptName: promptName & string) { + public isPromptEnabled(promptName: promptName) { try { - return !this._getOrThrow(promptName, false) + return !this._getOrThrow(promptName, false as never) } catch (e) { this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message) this.reset().catch((e) => @@ -645,9 +647,9 @@ function getPromptSettings(promptsKey: promptSettingsKey) { } } - public async disablePrompt(promptName: promptName & string) { + public async disablePrompt(promptName: promptName) { if (this.isPromptEnabled(promptName)) { - await this.update(promptName, true) + await this.update(promptName, true as never) } } diff --git a/packages/core/src/test/shared/settings.test.ts b/packages/core/src/test/shared/settings.test.ts index 08a31ff42f2..5d485489138 100644 --- a/packages/core/src/test/shared/settings.test.ts +++ b/packages/core/src/test/shared/settings.test.ts @@ -498,7 +498,7 @@ describe('PromptSetting', function () { it(scenario.desc, async () => { await settings.update(promptSettingKey, scenario.testValue) const before = settings.get(promptSettingKey, Object, {}) - const result = await sut.isPromptEnabled(promptName) + const result = sut.isPromptEnabled(promptName) assert.deepStrictEqual(result, scenario.expected) assert.deepStrictEqual( From e0747bf445640dc5d8a364bc75aa089aa7362fe0 Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 16 Dec 2024 10:27:13 -0500 Subject: [PATCH 13/14] remove unnecessary await --- packages/core/src/awsService/apprunner/commands/pauseService.ts | 2 +- packages/core/src/shared/settings.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/awsService/apprunner/commands/pauseService.ts b/packages/core/src/awsService/apprunner/commands/pauseService.ts index a1f3bac54c9..b2cbdee1cae 100644 --- a/packages/core/src/awsService/apprunner/commands/pauseService.ts +++ b/packages/core/src/awsService/apprunner/commands/pauseService.ts @@ -18,7 +18,7 @@ export async function pauseService(node: AppRunnerServiceNode): Promise { try { const prompts = ToolkitPromptSettings.instance - const shouldNotify = await prompts.isPromptEnabled('apprunnerNotifyPause') + const shouldNotify = prompts.isPromptEnabled('apprunnerNotifyPause') const notifyPrompt = localize( 'aws.apprunner.pauseService.notify', 'Your service will be unavailable while paused. ' + diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 54642697a7a..1fa50a8f1a6 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -624,7 +624,7 @@ export type ToolkitPromptSettings = InstanceType export const amazonQPrompts = settingsProps['amazonQ.suppressPrompts'] export const AmazonQPromptSettings = getPromptSettings('amazonQ.suppressPrompts') -export type AmazonQPromptSettings = InstanceType +export type AmazonQPromptSettings = InstanceType type promptSettingsKey = 'amazonQ.suppressPrompts' | 'aws.suppressPrompts' function getPromptSettings

(promptsKey: P) { From 4d8545ecb5591a3c53fecec29fb7ea27b1df276b Mon Sep 17 00:00:00 2001 From: hkobew Date: Mon, 16 Dec 2024 10:43:16 -0500 Subject: [PATCH 14/14] remove awaits --- packages/core/src/auth/sso/ssoAccessTokenProvider.ts | 2 +- .../core/src/awsService/apprunner/wizards/deploymentButton.ts | 2 +- packages/core/src/awsService/ecs/commands.ts | 4 ++-- packages/core/src/awsService/s3/fileViewerManager.ts | 2 +- packages/core/src/codecatalyst/activation.ts | 2 +- .../src/codewhisperer/commands/gettingStartedPageCommands.ts | 2 +- packages/core/src/codewhisperer/util/authUtil.ts | 2 +- packages/core/src/codewhisperer/vue/backend.ts | 2 +- packages/core/src/shared/awsContextCommands.ts | 2 +- packages/core/src/shared/extensionStartup.ts | 2 +- packages/core/src/shared/sam/activation.ts | 2 +- packages/core/src/shared/sam/sync.ts | 2 +- packages/core/src/shared/settings.ts | 3 +-- packages/core/src/shared/utilities/messages.ts | 2 +- 14 files changed, 15 insertions(+), 16 deletions(-) diff --git a/packages/core/src/auth/sso/ssoAccessTokenProvider.ts b/packages/core/src/auth/sso/ssoAccessTokenProvider.ts index bf9c620c2f3..6639e9f3832 100644 --- a/packages/core/src/auth/sso/ssoAccessTokenProvider.ts +++ b/packages/core/src/auth/sso/ssoAccessTokenProvider.ts @@ -808,7 +808,7 @@ class DiskCacheErrorMessage { : ToolkitPromptSettings.instance // We know 'ssoCacheError' is in all extension prompt settings - if (await promptSettings.isPromptEnabled('ssoCacheError')) { + if (promptSettings.isPromptEnabled('ssoCacheError')) { const result = await showMessage() if (result === dontShow) { await promptSettings.disablePrompt('ssoCacheError') diff --git a/packages/core/src/awsService/apprunner/wizards/deploymentButton.ts b/packages/core/src/awsService/apprunner/wizards/deploymentButton.ts index 24a98895970..dee77c05e97 100644 --- a/packages/core/src/awsService/apprunner/wizards/deploymentButton.ts +++ b/packages/core/src/awsService/apprunner/wizards/deploymentButton.ts @@ -32,7 +32,7 @@ function makeDeployButtons() { async function showDeploymentCostNotification(): Promise { const settings = ToolkitPromptSettings.instance - if (await settings.isPromptEnabled('apprunnerNotifyPricing')) { + if (settings.isPromptEnabled('apprunnerNotifyPricing')) { const notice = localize( 'aws.apprunner.createService.priceNotice.message', 'App Runner automatic deployments incur an additional cost.' diff --git a/packages/core/src/awsService/ecs/commands.ts b/packages/core/src/awsService/ecs/commands.ts index 5845793e7b2..acf3daa8047 100644 --- a/packages/core/src/awsService/ecs/commands.ts +++ b/packages/core/src/awsService/ecs/commands.ts @@ -32,7 +32,7 @@ async function runCommandWizard( const wizard = new CommandWizard( container, - await ToolkitPromptSettings.instance.isPromptEnabled('ecsRunCommand'), + ToolkitPromptSettings.instance.isPromptEnabled('ecsRunCommand'), command ) const response = await wizard.run() @@ -75,7 +75,7 @@ export async function toggleExecuteCommandFlag( 'Disabling command execution will change the state of resources in your AWS account, including but not limited to stopping and restarting the service.\n Continue?' ) - if (await settings.isPromptEnabled(prompt)) { + if (settings.isPromptEnabled(prompt)) { const choice = await window.showWarningMessage(warningMessage, yes, yesDontAskAgain, no) if (choice === undefined || choice === no) { throw new CancellationError('user') diff --git a/packages/core/src/awsService/s3/fileViewerManager.ts b/packages/core/src/awsService/s3/fileViewerManager.ts index 336737b027e..d800a3bfeee 100644 --- a/packages/core/src/awsService/s3/fileViewerManager.ts +++ b/packages/core/src/awsService/s3/fileViewerManager.ts @@ -346,7 +346,7 @@ export class S3FileViewerManager { } private async showEditNotification(): Promise { - if (!(await this.settings.isPromptEnabled(promptOnEditKey))) { + if (!this.settings.isPromptEnabled(promptOnEditKey)) { return } diff --git a/packages/core/src/codecatalyst/activation.ts b/packages/core/src/codecatalyst/activation.ts index 812766f5687..4a2385559f4 100644 --- a/packages/core/src/codecatalyst/activation.ts +++ b/packages/core/src/codecatalyst/activation.ts @@ -128,7 +128,7 @@ export async function activate(ctx: ExtContext): Promise { await showReadmeFileOnFirstLoad(ctx.extensionContext.workspaceState) const settings = ToolkitPromptSettings.instance - if (await settings.isPromptEnabled('remoteConnected')) { + if (settings.isPromptEnabled('remoteConnected')) { const message = localize( 'AWS.codecatalyst.connectedMessage', 'Welcome to your Amazon CodeCatalyst Dev Environment. For more options and information, view Dev Environment settings ({0} Extension > CodeCatalyst).', diff --git a/packages/core/src/codewhisperer/commands/gettingStartedPageCommands.ts b/packages/core/src/codewhisperer/commands/gettingStartedPageCommands.ts index 5036a9d3b5b..ab7c8e00afc 100644 --- a/packages/core/src/codewhisperer/commands/gettingStartedPageCommands.ts +++ b/packages/core/src/codewhisperer/commands/gettingStartedPageCommands.ts @@ -20,7 +20,7 @@ export class CodeWhispererCommandBackend { const prompts = AmazonQPromptSettings.instance // To check the condition If the user has already seen the welcome message - if (!(await prompts.isPromptEnabled('codeWhispererNewWelcomeMessage'))) { + if (!prompts.isPromptEnabled('codeWhispererNewWelcomeMessage')) { telemetry.ui_click.emit({ elementId: 'codewhisperer_Learn_ButtonClick', passive: true }) } return showCodeWhispererWebview(this.extContext, source) diff --git a/packages/core/src/codewhisperer/util/authUtil.ts b/packages/core/src/codewhisperer/util/authUtil.ts index ed2dfd66e6c..afb15aff133 100644 --- a/packages/core/src/codewhisperer/util/authUtil.ts +++ b/packages/core/src/codewhisperer/util/authUtil.ts @@ -366,7 +366,7 @@ export class AuthUtil { public async notifySessionConfiguration() { const suppressId = 'amazonQSessionConfigurationMessage' const settings = AmazonQPromptSettings.instance - const shouldShow = await settings.isPromptEnabled(suppressId) + const shouldShow = settings.isPromptEnabled(suppressId) if (!shouldShow) { return } diff --git a/packages/core/src/codewhisperer/vue/backend.ts b/packages/core/src/codewhisperer/vue/backend.ts index ec1ed818ec0..e4baecadc18 100644 --- a/packages/core/src/codewhisperer/vue/backend.ts +++ b/packages/core/src/codewhisperer/vue/backend.ts @@ -161,7 +161,7 @@ export async function showCodeWhispererWebview( ] const prompts = AmazonQPromptSettings.instance // To check the condition If the user has already seen the welcome message - if (await prompts.isPromptEnabled('codeWhispererNewWelcomeMessage')) { + if (prompts.isPromptEnabled('codeWhispererNewWelcomeMessage')) { telemetry.ui_click.emit({ elementId: 'codewhisperer_Learn_PageOpen', passive: true }) } else { telemetry.ui_click.emit({ elementId: 'codewhisperer_Learn_PageOpen', passive: false }) diff --git a/packages/core/src/shared/awsContextCommands.ts b/packages/core/src/shared/awsContextCommands.ts index b2016dd33c2..aaf439b3f02 100644 --- a/packages/core/src/shared/awsContextCommands.ts +++ b/packages/core/src/shared/awsContextCommands.ts @@ -65,7 +65,7 @@ export class AwsContextCommands { await this.editCredentials() if ( credentialsFiles.length === 0 && - (await ToolkitPromptSettings.instance.isPromptEnabled('createCredentialsProfile')) && + ToolkitPromptSettings.instance.isPromptEnabled('createCredentialsProfile') && (await this.promptCredentialsSetup()) ) { await this.onCommandCreateCredentialsProfile() diff --git a/packages/core/src/shared/extensionStartup.ts b/packages/core/src/shared/extensionStartup.ts index f4ed00e9543..fd5aab755e7 100644 --- a/packages/core/src/shared/extensionStartup.ts +++ b/packages/core/src/shared/extensionStartup.ts @@ -24,7 +24,7 @@ const localize = nls.loadMessageBundle() */ export async function maybeShowMinVscodeWarning(minVscode: string) { const settings = isAmazonQ() ? AmazonQPromptSettings.instance : ToolkitPromptSettings.instance - if (!(await settings.isPromptEnabled('minIdeVersion'))) { + if (!settings.isPromptEnabled('minIdeVersion')) { return } const updateButton = `Update ${vscode.env.appName}` diff --git a/packages/core/src/shared/sam/activation.ts b/packages/core/src/shared/sam/activation.ts index a19c9ff4acb..3f398968b19 100644 --- a/packages/core/src/shared/sam/activation.ts +++ b/packages/core/src/shared/sam/activation.ts @@ -323,7 +323,7 @@ async function createYamlExtensionPrompt(): Promise { // Show this only in VSCode since other VSCode-like IDEs (e.g. Theia) may // not have a marketplace or contain the YAML plugin. if ( - (await settings.isPromptEnabled('yamlExtPrompt')) && + settings.isPromptEnabled('yamlExtPrompt') && getIdeType() === 'vscode' && !vscode.extensions.getExtension(VSCODE_EXTENSION_ID.yaml) ) { diff --git a/packages/core/src/shared/sam/sync.ts b/packages/core/src/shared/sam/sync.ts index 9f4bdc6ab07..44fe6dbd141 100644 --- a/packages/core/src/shared/sam/sync.ts +++ b/packages/core/src/shared/sam/sync.ts @@ -520,7 +520,7 @@ async function updateSyncRecentResponse(region: string, key: string, value: stri } export async function confirmDevStack() { - const canPrompt = await ToolkitPromptSettings.instance.isPromptEnabled('samcliConfirmDevStack') + const canPrompt = ToolkitPromptSettings.instance.isPromptEnabled('samcliConfirmDevStack') if (!canPrompt) { return } diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 1fa50a8f1a6..f1c3e4bc026 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -625,9 +625,8 @@ export type ToolkitPromptSettings = InstanceType export const amazonQPrompts = settingsProps['amazonQ.suppressPrompts'] export const AmazonQPromptSettings = getPromptSettings('amazonQ.suppressPrompts') export type AmazonQPromptSettings = InstanceType -type promptSettingsKey = 'amazonQ.suppressPrompts' | 'aws.suppressPrompts' -function getPromptSettings

(promptsKey: P) { +function getPromptSettings

(promptsKey: P) { const prompts = settingsProps[promptsKey] type promptName = keyof typeof prompts & string return class AnonymousPromptSettings extends Settings.define( diff --git a/packages/core/src/shared/utilities/messages.ts b/packages/core/src/shared/utilities/messages.ts index 1812909321c..a961e983745 100644 --- a/packages/core/src/shared/utilities/messages.ts +++ b/packages/core/src/shared/utilities/messages.ts @@ -194,7 +194,7 @@ export async function showReauthenticateMessage({ reauthFunc: () => Promise source?: string }) { - const shouldShow = await settings.isPromptEnabled(suppressId as any) + const shouldShow = settings.isPromptEnabled(suppressId as any) if (!shouldShow) { return }