-
Notifications
You must be signed in to change notification settings - Fork 274
feat(amazonq): Added changes for override lsp artifacts #5429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
d2795d1
30ce060
aaca577
5a4dc9e
6b49fc8
c4ec818
a2ef3b0
b11347d
7f009bd
5e9fa9d
1ff048a
2d99e46
7df6549
aefe915
293423d
61188ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.settings | ||
|
|
||
| import com.intellij.openapi.components.BaseState | ||
| import com.intellij.openapi.components.PersistentStateComponent | ||
| import com.intellij.openapi.components.RoamingType | ||
| import com.intellij.openapi.components.Service | ||
| import com.intellij.openapi.components.State | ||
| import com.intellij.openapi.components.Storage | ||
| import com.intellij.openapi.components.service | ||
| import com.intellij.util.xmlb.annotations.Property | ||
|
|
||
| @Service | ||
|
Check warning on line 15 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
| @State(name = "lspSettings", storages = [Storage("aws.xml", roamingType = RoamingType.DISABLED)]) | ||
| class LspSettings : PersistentStateComponent<LspConfiguration> { | ||
| private var state = LspConfiguration() | ||
|
Check warning on line 18 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
|
|
||
| override fun getState(): LspConfiguration = state | ||
|
Check warning on line 20 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
|
|
||
| override fun loadState(state: LspConfiguration) { | ||
| this.state = state | ||
| } | ||
|
Check warning on line 24 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
|
|
||
| fun getArtifactPath() = state.artifactPath | ||
|
Check warning on line 26 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
|
|
||
| fun setArtifactPath(artifactPath: String?) { | ||
| if (artifactPath == null) { | ||
| state.artifactPath = "" | ||
|
Check warning on line 30 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
| } else { | ||
| state.artifactPath = artifactPath | ||
|
Check warning on line 32 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
| } | ||
| } | ||
|
Check warning on line 34 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
|
|
||
| companion object { | ||
| fun getInstance(): LspSettings = service() | ||
|
Check warning on line 37 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
| } | ||
| } | ||
|
|
||
| class LspConfiguration : BaseState() { | ||
| @get:Property | ||
| var artifactPath: String = "" | ||
|
Check warning on line 43 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package software.aws.toolkits.jetbrains.settings | ||
|
|
||
| import com.intellij.util.xmlb.XmlSerializer | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.jdom.output.XMLOutputter | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
LokeshDogga13 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import software.aws.toolkits.jetbrains.utils.xmlElement | ||
|
|
||
| class LspSettingsTest { | ||
| private lateinit var lspSettings: LspSettings | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| lspSettings = LspSettings() | ||
| lspSettings.loadState(LspConfiguration()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `artifact path is empty by default`() { | ||
| assertThat(lspSettings.getArtifactPath()).isEmpty() | ||
| } | ||
|
|
||
| @Test | ||
| fun `artifact path can be set`() { | ||
| lspSettings.setArtifactPath("test\\lsp.js") | ||
| assertThat(lspSettings.getArtifactPath()).isNotEmpty() | ||
| assertThat(lspSettings.getArtifactPath()).isEqualTo("test\\lsp.js") | ||
| } | ||
|
|
||
| @Test | ||
| fun `artifact path cannot be null`() { | ||
| lspSettings.setArtifactPath(null) | ||
| assertThat(lspSettings.getArtifactPath()).isEmpty() | ||
| } | ||
|
|
||
| @Test | ||
| fun `serialize settings to ensure backwards compatibility`() { | ||
| val element = xmlElement( | ||
| """ | ||
| <component name="LspSettings"> | ||
| </component> | ||
| """.trimIndent() | ||
| ) | ||
| lspSettings.setArtifactPath("temp\\lsp.js") | ||
|
|
||
| XmlSerializer.serializeInto(lspSettings.state, element) | ||
|
|
||
| val actual = XMLOutputter().outputString(element) | ||
|
|
||
| val expected = "<component name=\"LspSettings\">\n" + | ||
| "<option name=\"artifactPath\" value=\"temp\\lsp.js\" /></component>" | ||
|
|
||
| assertThat(actual).isEqualTo(expected) | ||
| } | ||
|
|
||
| @Test | ||
| fun `deserialize empty settings to ensure backwards compatibility`() { | ||
| val element = xmlElement( | ||
| """ | ||
| <component name="LspSettings"> | ||
| </component> | ||
| """ | ||
| ) | ||
| val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java) | ||
| assertThat(actual.artifactPath).isEmpty() | ||
| } | ||
|
|
||
| @Test | ||
| fun `deserialize existing settings to ensure backwards compatibility`() { | ||
| val element = xmlElement( | ||
| """ | ||
| <component name="LspSettings"> | ||
| <option name="artifactPath" value='temp\lsp.js'/> | ||
| </component> | ||
| """.trimIndent() | ||
| ) | ||
| val actual = XmlSerializer.deserialize(element, LspConfiguration::class.java) | ||
| assertThat(actual.artifactPath).isNotEmpty() | ||
| assertThat(actual.artifactPath).isEqualTo("temp\\lsp.js") | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.