Skip to content

Commit f3e405a

Browse files
committed
refactor and fix
1 parent 6fc8bda commit f3e405a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/core/src/codewhisperer/region/regionProfileManager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ const endpoints = createConstantMap({
4949
*/
5050
export type ProfileSwitchIntent = 'user' | 'auth' | 'update' | 'reload' | 'customization'
5151

52+
export type ProfileChangedEvent = {
53+
profile: RegionProfile | undefined
54+
intent: ProfileSwitchIntent
55+
}
56+
5257
export class RegionProfileManager {
5358
private static logger = getLogger()
5459
private _activeRegionProfile: RegionProfile | undefined
55-
private _onDidChangeRegionProfile = new vscode.EventEmitter<RegionProfile | undefined>()
60+
private _onDidChangeRegionProfile = new vscode.EventEmitter<ProfileChangedEvent>()
5661
public readonly onDidChangeRegionProfile = this._onDidChangeRegionProfile.event
5762

5863
// Store the last API results (for UI propuse) so we don't need to call service again if doesn't require "latest" result
@@ -205,13 +210,16 @@ export class RegionProfileManager {
205210
})
206211
}
207212

208-
await this._switchRegionProfile(regionProfile)
213+
await this._switchRegionProfile(regionProfile, source)
209214
}
210215

211-
private async _switchRegionProfile(regionProfile: RegionProfile | undefined) {
216+
private async _switchRegionProfile(regionProfile: RegionProfile | undefined, source: ProfileSwitchIntent) {
212217
this._activeRegionProfile = regionProfile
213218

214-
this._onDidChangeRegionProfile.fire(regionProfile)
219+
this._onDidChangeRegionProfile.fire({
220+
profile: regionProfile,
221+
intent: source,
222+
})
215223
// dont show if it's a default (fallback)
216224
if (regionProfile && this.profiles.length > 1) {
217225
void vscode.window.showInformationMessage(`You are using the ${regionProfile.name} profile for Q.`).then()

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Commands } from '../../shared/vscode/commands2'
1919
import { RegionProfile, vsCodeState } from '../models/model'
2020
import { pageableToCollection } from '../../shared/utilities/collectionUtils'
2121
import { isAwsError } from '../../shared/errors'
22+
import { ProfileChangedEvent } from '../region/regionProfileManager'
2223

2324
export class CustomizationProvider {
2425
constructor(
@@ -50,10 +51,13 @@ export class CustomizationProvider {
5051
}
5152
}
5253

53-
export const onProfileChangedListener: (profile: RegionProfile | undefined) => any = async (myProfile) => {
54+
export const onProfileChangedListener: (event: ProfileChangedEvent) => any = async (event) => {
55+
if (event.intent === 'customization') {
56+
return
57+
}
5458
const logger = getLogger()
5559
// TODO: To check how do we do we handle it when user signs out.
56-
if (!myProfile) {
60+
if (!event.profile) {
5761
await setSelectedCustomization(baseCustomization)
5862
return
5963
}
@@ -62,13 +66,13 @@ export const onProfileChangedListener: (profile: RegionProfile | undefined) => a
6266
const selectedCustomization = getSelectedCustomization()
6367
// No need to validate base customization which has empty arn.
6468
if (selectedCustomization.arn.length > 0) {
65-
const customizationProvider = await CustomizationProvider.init(myProfile)
69+
const customizationProvider = await CustomizationProvider.init(event.profile)
6670
const customizations = await customizationProvider.listAvailableCustomizations()
6771

6872
const r = customizations.find((it) => it.arn === selectedCustomization.arn)
6973
if (!r) {
7074
logger.debug(
71-
`profile ${myProfile.name} doesnt have access to customization ${selectedCustomization.name} but has access to ${customizations.map((it) => it.name)}`
75+
`profile ${event.profile.name} doesnt have access to customization ${selectedCustomization.name} but has access to ${customizations.map((it) => it.name)}`
7276
)
7377
await switchToBaseCustomizationAndNotify()
7478
}

0 commit comments

Comments
 (0)