Skip to content

Commit 7f90c20

Browse files
samgst-amazonrli
andauthored
feat(amazonq): add lsp configuration support for includeSuggestionsWithCodeReferences (#5480)
* add message and data classes * Update plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt Co-authored-by: Richard Li <[email protected]> --------- Co-authored-by: Richard Li <[email protected]>
1 parent e8a4bee commit 7f90c20

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
8282
AmazonQLspConstants.LSP_CW_CONFIGURATION_KEY -> {
8383
add(
8484
CodeWhispererLspConfiguration(
85-
shouldShareData = CodeWhispererSettings.getInstance().isMetricOptIn()
85+
shouldShareData = CodeWhispererSettings.getInstance().isMetricOptIn(),
86+
shouldShareCodeReferences = CodeWhispererSettings.getInstance().isIncludeCodeWithReference(),
8687
)
8788
)
8889
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspConstants.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
package software.aws.toolkits.jetbrains.services.amazonq.lsp
55

66
object AmazonQLspConstants {
7+
const val AWS_BUILDER_ID_URL = "https://view.awsapps.com/start"
78
const val LSP_CW_CONFIGURATION_KEY = "aws.codeWhisperer"
89
const val LSP_CW_OPT_OUT_KEY = "shareCodeWhispererContentWithAWS"
9-
const val AWS_BUILDER_ID_URL = "https://view.awsapps.com/start"
10+
const val LSP_CODE_REFERENCES_OPT_OUT_KEY = "includeSuggestionsWithCodeReferences"
1011
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/CodeWhispererLspConfiguration.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ import com.google.gson.annotations.SerializedName
88
data class CodeWhispererLspConfiguration(
99
@SerializedName(AmazonQLspConstants.LSP_CW_OPT_OUT_KEY)
1010
val shouldShareData: Boolean? = null,
11+
12+
@SerializedName(AmazonQLspConstants.LSP_CODE_REFERENCES_OPT_OUT_KEY)
13+
val shouldShareCodeReferences: Boolean? = null,
1114
)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class CodeWhispererSettings : PersistentStateComponent<CodeWhispererConfiguratio
2323

2424
fun toggleIncludeCodeWithReference(value: Boolean) {
2525
state.value[CodeWhispererConfigurationType.IsIncludeCodeWithReference] = value
26+
ProjectManager.getInstance().openProjects.forEach {
27+
if (it.isDisposed) {
28+
return@forEach
29+
}
30+
31+
AmazonQLspService.didChangeConfiguration(it)
32+
}
2633
}
2734

2835
fun isIncludeCodeWithReference() = state.value.getOrDefault(

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLanguageClientImplTest.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class AmazonQLanguageClientImplTest {
6565
assertThat(sut.configuration(configurationParams("aws.codeWhisperer")).get())
6666
.singleElement()
6767
.isEqualTo(
68-
CodeWhispererLspConfiguration(shouldShareData = false)
68+
CodeWhispererLspConfiguration(
69+
shouldShareData = false,
70+
shouldShareCodeReferences = false
71+
)
6972
)
7073
}
7174

@@ -75,7 +78,10 @@ class AmazonQLanguageClientImplTest {
7578
assertThat(sut.configuration(configurationParams("aws.codeWhisperer")).get())
7679
.singleElement()
7780
.isEqualTo(
78-
CodeWhispererLspConfiguration(shouldShareData = true)
81+
CodeWhispererLspConfiguration(
82+
shouldShareData = true,
83+
shouldShareCodeReferences = false
84+
)
7985
)
8086
}
8187

@@ -87,11 +93,15 @@ class AmazonQLanguageClientImplTest {
8793

8894
@Test
8995
fun `Gson serializes CodeWhispererLspConfiguration serializes correctly`() {
90-
val sut = CodeWhispererLspConfiguration(shouldShareData = true)
96+
val sut = CodeWhispererLspConfiguration(
97+
shouldShareData = true,
98+
shouldShareCodeReferences = true
99+
)
91100
assertThat(Gson().toJson(sut)).isEqualToIgnoringWhitespace(
92101
"""
93102
{
94-
"shareCodeWhispererContentWithAWS": true
103+
"shareCodeWhispererContentWithAWS": true,
104+
"includeSuggestionsWithCodeReferences": true
95105
}
96106
""".trimIndent()
97107
)

0 commit comments

Comments
 (0)