Skip to content

Commit ad8eee1

Browse files
fix circular depdendency
Moved the notify message function to a better location to avoid circular dependency Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 2a366ea commit ad8eee1

File tree

3 files changed

+52
-38
lines changed

3 files changed

+52
-38
lines changed

packages/core/src/codewhisperer/activation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import { SecurityIssueTreeViewProvider } from './service/securityIssueTreeViewPr
9595
import { setContext } from '../shared/vscode/setContext'
9696
import { syncSecurityIssueWebview } from './views/securityIssue/securityIssueWebview'
9797
import { detectCommentAboveLine } from '../shared/utilities/commentUtils'
98+
import { notifySelectDeveloperProfile } from './region/utils'
9899

99100
let localize: nls.LocalizeFunc
100101

@@ -382,7 +383,7 @@ export async function activate(context: ExtContext): Promise<void> {
382383
}
383384

384385
if (auth.requireProfileSelection()) {
385-
await auth.notifySelectProfile()
386+
await notifySelectDeveloperProfile()
386387
}
387388
},
388389
{ emit: false, functionId: { name: 'activateCwCore' } }
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import * as nls from 'vscode-nls'
6+
const localize = nls.loadMessageBundle()
7+
import { AmazonQPromptSettings } from '../../shared/settings'
8+
import { telemetry } from '../../shared/telemetry/telemetry'
9+
import vscode from 'vscode'
10+
import { selectRegionProfileCommand } from '../commands/basicCommands'
11+
import { placeholder } from '../../shared/vscode/commands2'
12+
import { toastMessage } from '../commands/types'
13+
14+
/**
15+
* Creates a toast message telling the user they need to select a Developer Profile
16+
*/
17+
export async function notifySelectDeveloperProfile() {
18+
const suppressId = 'amazonQSelectDeveloperProfile'
19+
const settings = AmazonQPromptSettings.instance
20+
const shouldShow = settings.isPromptEnabled(suppressId)
21+
if (!shouldShow) {
22+
return
23+
}
24+
25+
const message = localize(
26+
'aws.amazonq.profile.mustSelectMessage',
27+
'You must select a Q Developer Profile for Amazon Q features to work.'
28+
)
29+
const selectProfile = 'Select Profile'
30+
const dontShowAgain = 'Dont Show Again'
31+
32+
await telemetry.toolkit_showNotification.run(async () => {
33+
telemetry.record({ id: 'mustSelectDeveloperProfileMessage' })
34+
void vscode.window.showWarningMessage(message, selectProfile, dontShowAgain).then(async (resp) => {
35+
await telemetry.toolkit_invokeAction.run(async () => {
36+
if (resp === selectProfile) {
37+
// Show Profile
38+
telemetry.record({ action: 'select' })
39+
void selectRegionProfileCommand.execute(placeholder, toastMessage)
40+
} else if (resp === dontShowAgain) {
41+
telemetry.record({ action: 'dontShowAgain' })
42+
await settings.disablePrompt(suppressId)
43+
} else {
44+
telemetry.record({ action: 'ignore' })
45+
}
46+
})
47+
})
48+
})
49+
}

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ import { withTelemetryContext } from '../../shared/telemetry/util'
4646
import { focusAmazonQPanel } from '../../codewhispererChat/commands/registerCommands'
4747
import { throttle } from 'lodash'
4848
import { RegionProfileManager } from '../region/regionProfileManager'
49-
import { selectRegionProfileCommand } from '../commands/basicCommands'
50-
import { toastMessage } from '../commands/types'
49+
5150
/** Backwards compatibility for connections w pre-chat scopes */
5251
export const codeWhispererCoreScopes = [...scopesCodeWhispererCore]
5352
export const codeWhispererChatScopes = [...codeWhispererCoreScopes, ...scopesCodeWhispererChat]
@@ -411,41 +410,6 @@ export class AuthUtil {
411410
})
412411
}
413412

414-
/** Notify the user they need to select a Developer Profile */
415-
public async notifySelectProfile() {
416-
const suppressId = 'amazonQSelectDeveloperProfile'
417-
const settings = AmazonQPromptSettings.instance
418-
const shouldShow = settings.isPromptEnabled(suppressId)
419-
if (!shouldShow) {
420-
return
421-
}
422-
423-
const message = localize(
424-
'aws.amazonq.profile.mustSelectMessage',
425-
'You must select a Q Developer Profile for Amazon Q features to work.'
426-
)
427-
const selectProfile = 'Select Profile'
428-
const dontShowAgain = 'Dont Show Again'
429-
430-
await telemetry.toolkit_showNotification.run(async () => {
431-
telemetry.record({ id: 'mustSelectDeveloperProfileMessage' })
432-
void vscode.window.showWarningMessage(message, selectProfile, dontShowAgain).then(async (resp) => {
433-
await telemetry.toolkit_invokeAction.run(async () => {
434-
if (resp === selectProfile) {
435-
// Show Profile
436-
telemetry.record({ action: 'select' })
437-
void selectRegionProfileCommand.execute(placeholder, toastMessage)
438-
} else if (resp === dontShowAgain) {
439-
telemetry.record({ action: 'dontShowAgain' })
440-
await settings.disablePrompt(suppressId)
441-
} else {
442-
telemetry.record({ action: 'ignore' })
443-
}
444-
})
445-
})
446-
})
447-
}
448-
449413
@withTelemetryContext({ name: 'notifyReauthenticate', class: authClassName })
450414
public async notifyReauthenticate(isAutoTrigger?: boolean) {
451415
void this.showReauthenticatePrompt(isAutoTrigger)

0 commit comments

Comments
 (0)