Skip to content

Commit 28e9f48

Browse files
committed
revise activate method and add a func to refresh serviceArn
1 parent d148b66 commit 28e9f48

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/migration/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererModelConfigurator.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ interface CodeWhispererModelConfigurator {
3535
*/
3636
fun getNewUpdate(connectionId: String): Collection<CustomizationUiItem>?
3737

38+
/**
39+
* Refreshes the default customization ARN by retrieving the latest value from the feature configuration service.
40+
*/
41+
fun refreshDefaultCustomizationArn(project: Project)
42+
3843
companion object {
3944
fun getInstance(): CodeWhispererModelConfigurator = service()
4045
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/customization/CodeWhispererModelConfigurator.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
7676

7777
private val hasShownNewCustomizationNotification = AtomicBoolean(false)
7878

79+
private var serviceDefaultArn: String? = null
80+
7981
override fun showConfigDialog(project: Project) {
8082
runInEdt {
8183
calculateIfIamIdentityCenterConnection(project) {
@@ -165,16 +167,7 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
165167
override fun activeCustomization(project: Project): CodeWhispererCustomization? {
166168
val selectedCustomization = calculateIfIamIdentityCenterConnection(project) { connectionIdToActiveCustomizationArn[it.id] }
167169

168-
if (selectedCustomization != null) {
169-
return selectedCustomization
170-
} else {
171-
val customizationOverride = CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()
172-
if (customizationOverride == null || customizationOverride.value.stringValue().isEmpty()) return null
173-
return CodeWhispererCustomization(
174-
arn = customizationOverride.value.stringValue(),
175-
name = customizationOverride.variation,
176-
)
177-
}
170+
return selectedCustomization
178171
}
179172

180173
override fun switchCustomization(project: Project, newCustomization: CodeWhispererCustomization?) {
@@ -234,12 +227,22 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
234227
} ?: false
235228
}
236229

230+
override fun refreshDefaultCustomizationArn(project: Project) {
231+
CodeWhispererFeatureConfigService.getInstance().getCustomizationFeature()?.let { customization ->
232+
if (customization.value.stringValue() != serviceDefaultArn) {
233+
serviceDefaultArn = customization.value.stringValue()
234+
switchCustomization(project, CodeWhispererCustomization(customization.value.stringValue(), customization.variation))
235+
}
236+
}
237+
}
238+
237239
override fun getNewUpdate(connectionId: String) = connectionToCustomizationUiItems[connectionId]
238240

239241
override fun getState(): CodeWhispererCustomizationState {
240242
val state = CodeWhispererCustomizationState()
241243
state.connectionIdToActiveCustomizationArn.putAll(this.connectionIdToActiveCustomizationArn)
242244
state.previousAvailableCustomizations.putAll(this.connectionToCustomizationsShownLastTime)
245+
state.serviceDefaultArn = this.serviceDefaultArn
243246

244247
return state
245248
}
@@ -250,6 +253,8 @@ class DefaultCodeWhispererModelConfigurator : CodeWhispererModelConfigurator, Pe
250253

251254
connectionToCustomizationsShownLastTime.clear()
252255
connectionToCustomizationsShownLastTime.putAll(state.previousAvailableCustomizations)
256+
257+
this.serviceDefaultArn = state.serviceDefaultArn
253258
}
254259

255260
override fun dispose() {}
@@ -280,6 +285,10 @@ class CodeWhispererCustomizationState : BaseState() {
280285
@get:Property
281286
@get:MapAnnotation
282287
val previousAvailableCustomizations by map<String, MutableList<String>>()
288+
289+
@get:Property
290+
@get:MapAnnotation
291+
var serviceDefaultArn by string()
283292
}
284293

285294
data class CustomizationUiItem(

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/startup/CodeWhispererProjectStartupActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CodeWhispererProjectStartupActivity : StartupActivity.DumbAware {
6363
calculateIfIamIdentityCenterConnection(project) {
6464
pluginAwareExecuteOnPooledThread {
6565
CodeWhispererModelConfigurator.getInstance().listCustomizations(project, passive = true)
66+
CodeWhispererModelConfigurator.getInstance().refreshDefaultCustomizationArn(project)
6667
}
6768
}
6869

0 commit comments

Comments
 (0)