Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
018d719
run branch check on PRs only
Hweinstock Dec 9, 2024
d03a2da
use event branch name
Hweinstock Dec 9, 2024
4fb8e66
change wording
Hweinstock Dec 9, 2024
cdecab6
add extra check
Hweinstock Dec 9, 2024
f2900e5
switch to single quotes
Hweinstock Dec 9, 2024
902de77
Merge branch 'aws:master' into master
Hweinstock Dec 9, 2024
bf03fd3
Merge branch 'aws:master' into master
Hweinstock Dec 10, 2024
4cd5400
Merge branch 'aws:master' into master
Hweinstock Dec 10, 2024
0234303
Merge branch 'aws:master' into master
Hweinstock Dec 11, 2024
f988458
Merge branch 'aws:master' into master
Hweinstock Dec 12, 2024
54be0b3
Merge branch 'aws:master' into master
Hweinstock Dec 12, 2024
d4f7dda
Merge branch 'aws:master' into master
Hweinstock Dec 12, 2024
33f900a
Merge branch 'aws:master' into master
Hweinstock Dec 12, 2024
e16fe17
factor out to general isEnabled function
Hweinstock Dec 13, 2024
4498a73
avoid using same function for experiment
Hweinstock Dec 13, 2024
e9b39f2
factor out other method
Hweinstock Dec 13, 2024
df97e33
move code to be adjacent
Hweinstock Dec 13, 2024
ea22122
generate class based on prompt
Hweinstock Dec 13, 2024
7c55670
Merge branch 'aws:master' into master
Hweinstock Dec 16, 2024
78dd426
Merge branch 'master' into settingsRefactor
Hweinstock Dec 16, 2024
71fc1d9
fix type problem
Hweinstock Dec 16, 2024
44a7613
export type as well as value
Hweinstock Dec 16, 2024
e0747bf
remove unnecessary await
Hweinstock Dec 16, 2024
4d8545e
remove awaits
Hweinstock Dec 16, 2024
d363ea6
Merge branch 'master' into settingsRefactor
Hweinstock Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/auth/sso/ssoAccessTokenProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a welcome change 👍
Not a strong reason for this function to be async

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const result = await showMessage()
if (result === dontShow) {
await promptSettings.disablePrompt('ssoCacheError')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function pauseService(node: AppRunnerServiceNode): Promise<void> {

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. ' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function makeDeployButtons() {
async function showDeploymentCostNotification(): Promise<void> {
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.'
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/awsService/ecs/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/awsService/s3/fileViewerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class S3FileViewerManager {
}

private async showEditNotification(): Promise<void> {
if (!(await this.settings.isPromptEnabled(promptOnEditKey))) {
if (!this.settings.isPromptEnabled(promptOnEditKey)) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codecatalyst/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function activate(ctx: ExtContext): Promise<void> {
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).',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codewhisperer/util/authUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/codewhisperer/vue/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/awsContextCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/extensionStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/sam/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async function createYamlExtensionPrompt(): Promise<void> {
// 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)
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/sam/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
92 changes: 34 additions & 58 deletions packages/core/src/shared/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export function fromExtensionManifest<T extends TypeDescriptor & Partial<Section
*
* ### Usage:
* ```
* if (await settings.isPromptEnabled('myPromptName')) {
* if (settings.isPromptEnabled('myPromptName')) {
* // Show some sort of prompt
* const userResponse = await promptUser()
*
Expand All @@ -619,68 +619,44 @@ export function fromExtensionManifest<T extends TypeDescriptor & Partial<Section
* core lib as necessary.
*/
export const toolkitPrompts = settingsProps['aws.suppressPrompts']
type toolkitPromptName = keyof typeof toolkitPrompts
export class ToolkitPromptSettings
extends Settings.define(
'aws.suppressPrompts',
toRecord(keys(toolkitPrompts), () => Boolean)
)
implements PromptSettings
{
public async isPromptEnabled(promptName: toolkitPromptName): Promise<boolean> {
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 async disablePrompt(promptName: toolkitPromptName): Promise<void> {
if (await this.isPromptEnabled(promptName)) {
await this.update(promptName, true)
}
}

static #instance: ToolkitPromptSettings

public static get instance() {
return (this.#instance ??= new this())
}
}
export const ToolkitPromptSettings = getPromptSettings('aws.suppressPrompts')
export type ToolkitPromptSettings = InstanceType<typeof ToolkitPromptSettings>

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 async isPromptEnabled(promptName: amazonQPromptName): Promise<boolean> {
try {
return !this._getOrThrow(promptName, false)
} catch (e) {
this._log('prompt check for "%s" failed: %s', promptName, (e as Error).message)
await this.reset()
export const AmazonQPromptSettings = getPromptSettings('amazonQ.suppressPrompts')
export type AmazonQPromptSettings = InstanceType<typeof AmazonQPromptSettings>

function getPromptSettings<P extends 'amazonQ.suppressPrompts' | 'aws.suppressPrompts'>(promptsKey: P) {
const prompts = settingsProps[promptsKey]
type promptName = keyof typeof prompts & string
return class AnonymousPromptSettings extends Settings.define(
promptsKey,
toRecord(keys(prompts), () => Boolean)
) {
public isPromptEnabled(promptName: promptName) {
try {
return !this._getOrThrow(promptName, false as never)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe there is an issue with how I setup types since I need the cast here.

} 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)
)

return true
return true
}
}
}

public async disablePrompt(promptName: amazonQPromptName): Promise<void> {
if (await this.isPromptEnabled(promptName)) {
await this.update(promptName, true)
public async disablePrompt(promptName: promptName) {
if (this.isPromptEnabled(promptName)) {
await this.update(promptName, true as never)
}
}
}

static #instance: AmazonQPromptSettings
static #instance: AnonymousPromptSettings

public static get instance() {
return (this.#instance ??= new this())
public static get instance() {
return (this.#instance ??= new this())
}
}
}

Expand All @@ -689,10 +665,10 @@ export class AmazonQPromptSettings
* 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): Promise<boolean>
isPromptEnabled(promptName: AllPromptNames): boolean
disablePrompt(promptName: AllPromptNames): Promise<void>
}

Expand All @@ -708,7 +684,7 @@ type ExperimentName = keyof typeof experiments
* ### Usage:
* ```
* function myExperimentalFeature(): void {
* if (!(await settings.isExperimentEnabled('myExperimentalFeature'))) {
* if (!( settings.isExperimentEnabled('myExperimentalFeature'))) {
* return
* }
*
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/utilities/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export async function showReauthenticateMessage({
reauthFunc: () => Promise<void>
source?: string
}) {
const shouldShow = await settings.isPromptEnabled(suppressId as any)
const shouldShow = settings.isPromptEnabled(suppressId as any)
if (!shouldShow) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/shared/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading