Skip to content

Commit 84b0f7d

Browse files
feat(amazonq): Added changes for override lsp artifacts (#5429)
1 parent 954096d commit 84b0f7d

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.settings
55

66
import com.intellij.icons.AllIcons
77
import com.intellij.ide.DataManager
8+
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
89
import com.intellij.openapi.options.BoundConfigurable
910
import com.intellij.openapi.options.Configurable
1011
import com.intellij.openapi.options.SearchableConfigurable
1112
import com.intellij.openapi.options.ex.Settings
1213
import com.intellij.openapi.project.Project
14+
import com.intellij.openapi.ui.emptyText
1315
import com.intellij.ui.components.ActionLink
1416
import com.intellij.ui.components.fields.ExpandableTextField
17+
import com.intellij.ui.dsl.builder.Align
1518
import com.intellij.ui.dsl.builder.bindIntText
1619
import com.intellij.ui.dsl.builder.bindSelected
1720
import com.intellij.ui.dsl.builder.bindText
@@ -24,6 +27,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.credentials.CodeWh
2427
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
2528
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isCodeWhispererEnabled
2629
import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings
30+
import software.aws.toolkits.jetbrains.settings.LspSettings
2731
import software.aws.toolkits.resources.message
2832
import java.awt.Font
2933
import java.util.concurrent.TimeUnit
@@ -61,6 +65,24 @@ class CodeWhispererConfigurable(private val project: Project) :
6165
}
6266
}
6367

68+
group(message("amazonqFeatureDev.placeholder.lsp")) {
69+
row(message("amazonqFeatureDev.placeholder.select_lsp_artifact")) {
70+
val fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFileDescriptor()
71+
fileChooserDescriptor.isForcedToUseIdeaFileChooser = true
72+
73+
textFieldWithBrowseButton(fileChooserDescriptor = fileChooserDescriptor)
74+
.bindText(
75+
{ LspSettings.getInstance().getArtifactPath() },
76+
{ LspSettings.getInstance().setArtifactPath(it.takeIf { v -> v.isNotBlank() }) }
77+
)
78+
.applyToComponent {
79+
emptyText.text = "Choose a file to upload"
80+
}
81+
.resizableColumn()
82+
.align(Align.FILL)
83+
}
84+
}
85+
6486
group(message("aws.settings.codewhisperer.group.inline_suggestions")) {
6587
row {
6688
checkBox(message("aws.settings.codewhisperer.include_code_with_reference")).apply {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.settings
5+
6+
import com.intellij.openapi.components.BaseState
7+
import com.intellij.openapi.components.PersistentStateComponent
8+
import com.intellij.openapi.components.RoamingType
9+
import com.intellij.openapi.components.Service
10+
import com.intellij.openapi.components.State
11+
import com.intellij.openapi.components.Storage
12+
import com.intellij.openapi.components.service
13+
import com.intellij.util.xmlb.annotations.Property
14+
15+
@Service
16+
@State(name = "lspSettings", storages = [Storage("aws.xml", roamingType = RoamingType.DISABLED)])
17+
class LspSettings : PersistentStateComponent<LspConfiguration> {
18+
private var state = LspConfiguration()
19+
20+
override fun getState(): LspConfiguration = state
21+
22+
override fun loadState(state: LspConfiguration) {
23+
this.state = state
24+
}
25+
26+
fun getArtifactPath() = state.artifactPath
27+
28+
fun setArtifactPath(artifactPath: String?) {
29+
if (artifactPath == null) {
30+
state.artifactPath = ""
31+
} else {
32+
state.artifactPath = artifactPath
33+
}
34+
}
35+
36+
companion object {
37+
fun getInstance(): LspSettings = service()
38+
}
39+
}
40+
41+
class LspConfiguration : BaseState() {
42+
@get:Property
43+
var artifactPath: String = ""
44+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.settings
5+
6+
import com.intellij.util.xmlb.XmlSerializer
7+
import org.assertj.core.api.Assertions.assertThat
8+
import org.jdom.output.XMLOutputter
9+
import org.junit.jupiter.api.BeforeEach
10+
import org.junit.jupiter.api.Test
11+
import software.aws.toolkits.jetbrains.utils.xmlElement
12+
13+
class LspSettingsTest {
14+
private lateinit var lspSettings: LspSettings
15+
16+
@BeforeEach
17+
fun setUp() {
18+
lspSettings = LspSettings()
19+
lspSettings.loadState(LspConfiguration())
20+
}
21+
22+
@Test
23+
fun `artifact path is empty by default`() {
24+
assertThat(lspSettings.getArtifactPath()).isEmpty()
25+
}
26+
27+
@Test
28+
fun `artifact path can be set`() {
29+
lspSettings.setArtifactPath("test\\lsp.js")
30+
assertThat(lspSettings.getArtifactPath()).isNotEmpty()
31+
assertThat(lspSettings.getArtifactPath()).isEqualTo("test\\lsp.js")
32+
}
33+
34+
@Test
35+
fun `artifact path cannot be null`() {
36+
lspSettings.setArtifactPath(null)
37+
assertThat(lspSettings.getArtifactPath()).isEmpty()
38+
}
39+
40+
@Test
41+
fun `serialize settings to ensure backwards compatibility`() {
42+
val element = xmlElement(
43+
"""
44+
<component name="LspSettings">
45+
</component>
46+
""".trimIndent()
47+
)
48+
lspSettings.setArtifactPath("temp\\lsp.js")
49+
50+
XmlSerializer.serializeInto(lspSettings.state, element)
51+
52+
val actual = XMLOutputter().outputString(element)
53+
54+
val expected = "<component name=\"LspSettings\">\n" +
55+
"<option name=\"artifactPath\" value=\"temp\\lsp.js\" /></component>"
56+
57+
assertThat(actual).isEqualTo(expected)
58+
}
59+
60+
@Test
61+
fun `deserialize empty settings to ensure backwards compatibility`() {
62+
val element = xmlElement(
63+
"""
64+
<component name="LspSettings">
65+
</component>
66+
"""
67+
)
68+
val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java)
69+
assertThat(actual.artifactPath).isEmpty()
70+
}
71+
72+
@Test
73+
fun `deserialize existing settings to ensure backwards compatibility`() {
74+
val element = xmlElement(
75+
"""
76+
<component name="LspSettings">
77+
<option name="artifactPath" value='temp\lsp.js'/>
78+
</component>
79+
""".trimIndent()
80+
)
81+
val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java)
82+
assertThat(actual.artifactPath).isNotEmpty()
83+
assertThat(actual.artifactPath).isEqualTo("temp\\lsp.js")
84+
}
85+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ amazonqFeatureDev.placeholder.closed_session=Open a new chat tab to continue
143143
amazonqFeatureDev.placeholder.context_gathering_complete=Gathering context...
144144
amazonqFeatureDev.placeholder.downloading_and_extracting_lsp_artifacts=Downloading and Extracting Lsp Artifacts...
145145
amazonqFeatureDev.placeholder.generating_code=Generating code...
146+
amazonqFeatureDev.placeholder.lsp=LSP
146147
amazonqFeatureDev.placeholder.new_plan=Describe your task or issue in as much detail as possible
147148
amazonqFeatureDev.placeholder.provide_code_feedback=Provide feedback or comments
149+
amazonqFeatureDev.placeholder.select_lsp_artifact=Select LSP Artifact
148150
amazonqFeatureDev.placeholder.write_new_prompt=Write a new prompt
149151
apprunner.action.configure=Configure Service
150152
apprunner.action.create.service=Create Service...

0 commit comments

Comments
 (0)