Skip to content

Commit 86e993e

Browse files
authored
docs(amazonq): Update autobuild setting strings (#5301)
Improves the formatting and strings presented to customers when the allow /dev to run code and test commands automatically. Also includes minor variable name changes to improve internal consistency.
1 parent da0ce18 commit 86e993e

File tree

6 files changed

+108
-29
lines changed

6 files changed

+108
-29
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class FeatureDevController(
727727
return
728728
}
729729

730-
val codeWhispererSettings = CodeWhispererSettings.getInstance().getAutoBuildFeatureConfiguration()
730+
val codeWhispererSettings = CodeWhispererSettings.getInstance().getAutoBuildSetting()
731731
val hasDevFile = session.context.checkForDevFile()
732732
val isPromptedForAutoBuildFeature = codeWhispererSettings.containsKey(session.context.getWorkspaceRoot())
733733

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,6 @@ class CodeWhispererConfigurable(private val project: Project) :
125125
}
126126
}
127127

128-
group(message("aws.settings.codewhisperer.allow_q_dev_build_test_commands")) {
129-
row {
130-
val settings = codeWhispererSettings.getAutoBuildFeatureConfiguration()
131-
for ((key) in settings) {
132-
checkBox(key).apply {
133-
connect.subscribe(
134-
ToolkitConnectionManagerListener.TOPIC,
135-
object : ToolkitConnectionManagerListener {
136-
override fun activeConnectionChanged(newConnection: ToolkitConnection?) {
137-
enabled(isCodeWhispererEnabled(project))
138-
}
139-
}
140-
)
141-
142-
bindSelected(
143-
getter = { codeWhispererSettings.isAutoBuildFeatureEnabled(key) },
144-
setter = { newValue -> codeWhispererSettings.toggleAutoBuildFeature(key, newValue) }
145-
)
146-
}
147-
}
148-
}
149-
}
150-
151128
group(message("aws.settings.codewhisperer.group.q_chat")) {
152129
row {
153130
checkBox(message("aws.settings.codewhisperer.project_context")).apply {
@@ -214,6 +191,35 @@ class CodeWhispererConfigurable(private val project: Project) :
214191
}
215192
}
216193

194+
val autoBuildSetting = codeWhispererSettings.getAutoBuildSetting()
195+
if (autoBuildSetting.isNotEmpty()) {
196+
group(message("aws.settings.codewhisperer.feature_development")) {
197+
row {
198+
text(message("aws.settings.codewhisperer.feature_development.allow_running_code_and_test_commands"))
199+
}
200+
row {
201+
val settings = codeWhispererSettings.getAutoBuildSetting()
202+
for ((key) in settings) {
203+
checkBox(key).apply {
204+
connect.subscribe(
205+
ToolkitConnectionManagerListener.TOPIC,
206+
object : ToolkitConnectionManagerListener {
207+
override fun activeConnectionChanged(newConnection: ToolkitConnection?) {
208+
enabled(isCodeWhispererEnabled(project))
209+
}
210+
}
211+
)
212+
213+
bindSelected(
214+
getter = { codeWhispererSettings.isAutoBuildFeatureEnabled(key) },
215+
setter = { newValue -> codeWhispererSettings.toggleAutoBuildFeature(key, newValue) }
216+
)
217+
}
218+
}
219+
}
220+
}
221+
}
222+
217223
group(message("aws.settings.codewhisperer.code_review")) {
218224
row {
219225
ExpandableTextField(ParametersListUtil.COLON_LINE_PARSER, ParametersListUtil.COLON_LINE_JOINER).also {

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererConfigurableTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.mockito.kotlin.doNothing
1313
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
1414
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanManager
1515
import software.aws.toolkits.jetbrains.services.codewhisperer.settings.CodeWhispererConfigurable
16+
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
1617
import software.aws.toolkits.resources.message
1718
import javax.swing.JCheckBox
1819
import javax.swing.JComponent

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererSettingsTest.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import com.intellij.openapi.wm.ToolWindowManager
1212
import com.intellij.openapi.wm.impl.status.widget.StatusBarWidgetsManager
1313
import com.intellij.testFramework.replaceService
1414
import com.intellij.testFramework.runInEdtAndWait
15+
import com.intellij.util.xmlb.XmlSerializer
1516
import org.assertj.core.api.Assertions.assertThat
17+
import org.jdom.output.XMLOutputter
1618
import org.junit.Before
1719
import org.junit.Ignore
1820
import org.junit.Test
@@ -30,6 +32,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.status.CodeWhisper
3032
import software.aws.toolkits.jetbrains.services.codewhisperer.toolwindow.CodeWhispererCodeReferenceToolWindowFactory
3133
import software.aws.toolkits.jetbrains.settings.CodeWhispererConfiguration
3234
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
35+
import software.aws.toolkits.jetbrains.utils.xmlElement
3336
import kotlin.test.fail
3437

3538
class CodeWhispererSettingsTest : CodeWhispererTestBase() {
@@ -145,6 +148,70 @@ class CodeWhispererSettingsTest : CodeWhispererTestBase() {
145148
assertThat(settingsManager.isIncludeCodeWithReference()).isEqualTo(true)
146149
}
147150
}
151+
152+
@Test
153+
fun `serialize settings to ensure backwards compatibility`() {
154+
val element = xmlElement(
155+
"""
156+
<component name="CodeWhispererSettings">
157+
</component>
158+
""".trimIndent()
159+
)
160+
161+
val settings = CodeWhispererSettings.getInstance()
162+
settings.toggleAutoBuildFeature("project1", true)
163+
164+
XmlSerializer.serializeInto(settings.state, element)
165+
166+
val actual = XMLOutputter().outputString(element)
167+
val expected = "<component name=\"CodeWhispererSettings\">\n" +
168+
"<option name=\"autoBuildSetting\">" +
169+
"<map><entry key=\"project1\" value=\"true\" />" +
170+
"</map>" +
171+
"</option>" +
172+
"<option name=\"value\">" +
173+
"<map><entry key=\"IsIncludeCodeWithReference\" value=\"true\" />" +
174+
"</map>" +
175+
"</option>" +
176+
"</component>"
177+
178+
assertThat(actual).isEqualTo(expected)
179+
}
180+
181+
@Test
182+
fun `deserialize empty settings to ensure backwards compatibility`() {
183+
val element = xmlElement(
184+
"""
185+
<component name="CodeWhispererSettings">
186+
</component>
187+
"""
188+
)
189+
val actual = XmlSerializer.deserialize(element, CodeWhispererConfiguration::class.java)
190+
assertThat(actual.autoBuildSetting).hasSize(0)
191+
}
192+
193+
@Test
194+
fun `deserialize existing settings to ensure backwards compatibility`() {
195+
val element = xmlElement(
196+
"""
197+
<component name="CodeWhispererSettings">
198+
<option name="autoBuildSetting">
199+
<map>
200+
<entry key="project1" value="true" />
201+
</map>
202+
</option>
203+
<option>
204+
<map>
205+
<entry key="IsIncludeCodeWithReference" value="true" />
206+
</map>
207+
</option>
208+
</component>
209+
""".trimIndent()
210+
)
211+
val actual = XmlSerializer.deserialize(element, CodeWhispererConfiguration::class.java)
212+
assertThat(actual.autoBuildSetting).hasSize(1)
213+
assertThat(actual.autoBuildSetting["project1"]).isTrue()
214+
}
148215
}
149216

150217
class CodeWhispererSettingUnitTest {

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/CodeWhispererSettings.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class CodeWhispererSettings : PersistentStateComponent<CodeWhispererConfiguratio
2525
false
2626
)
2727

28-
fun getAutoBuildFeatureConfiguration() = state.projectAutoBuildConfigurationMap
28+
fun getAutoBuildSetting() = state.autoBuildSetting
2929

3030
fun toggleAutoBuildFeature(project: String?, value: Boolean) {
3131
if (project == null) return
3232

33-
state.projectAutoBuildConfigurationMap[project] = value
33+
state.autoBuildSetting[project] = value
3434
}
3535

36-
fun isAutoBuildFeatureEnabled(project: String?) = state.projectAutoBuildConfigurationMap.getOrDefault(project, false)
36+
fun isAutoBuildFeatureEnabled(project: String?) = state.autoBuildSetting.getOrDefault(project, false)
3737

3838
fun toggleImportAdder(value: Boolean) {
3939
state.value[CodeWhispererConfigurationType.IsImportAdderEnabled] = value
@@ -131,15 +131,18 @@ class CodeWhispererSettings : PersistentStateComponent<CodeWhispererConfiguratio
131131
value.putAll(state.value)
132132
intValue.putAll(state.intValue)
133133
stringValue.putAll(state.stringValue)
134+
autoBuildSetting.putAll(state.autoBuildSetting)
134135
}
135136

136137
override fun loadState(state: CodeWhispererConfiguration) {
137138
this.state.value.clear()
138139
this.state.intValue.clear()
139140
this.state.stringValue.clear()
141+
this.state.autoBuildSetting.clear()
140142
this.state.value.putAll(state.value)
141143
this.state.intValue.putAll(state.intValue)
142144
this.state.stringValue.putAll(state.stringValue)
145+
this.state.autoBuildSetting.putAll(state.autoBuildSetting)
143146
}
144147
}
145148

@@ -153,7 +156,8 @@ class CodeWhispererConfiguration : BaseState() {
153156
@get:Property
154157
val stringValue by map<CodeWhispererStringConfigurationType, String>()
155158

156-
val projectAutoBuildConfigurationMap by map<String, Boolean>()
159+
@get:Property
160+
val autoBuildSetting by map<String, Boolean>()
157161
}
158162

159163
enum class CodeWhispererConfigurationType {

plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ aws.settings.auto_update.notification_enable.tooltip=If unchecked, updates will
266266
aws.settings.auto_update.progress.message=Updating AWS plugins
267267
aws.settings.auto_update.text=Automatically install plugin updates when available
268268
aws.settings.aws_cli_settings=AWS CLI Settings
269-
aws.settings.codewhisperer.allow_q_dev_build_test_commands=Amazon Q: Allow Q /dev to run code and test commands
269+
aws.settings.codewhisperer.feature_development=Feature Development
270+
aws.settings.codewhisperer.feature_development.allow_running_code_and_test_commands=Allow /dev to run code and test commands
270271
aws.settings.codewhisperer.automatic_import_adder=Imports recommendation
271272
aws.settings.codewhisperer.automatic_import_adder.tooltip=Amazon Q will add import statements with code suggestions when necessary
272273
aws.settings.codewhisperer.code_review=Code Review

0 commit comments

Comments
 (0)