Skip to content

Commit 9109943

Browse files
authored
fix(amazonq): fix LinkageError when starting AmazonQLspService (attempt 2) (#5627)
In certain IDE environments, for example when user has the latest Scala plugin, Amazon Q attempts to load lsp4j through transitive optional dependencies instead of through the IDE. Ideally we do not bundle the library, but this is not possible until JetBrains can guarantee stronger isolation between plugins As part of this we optimistically exclude Gson in hopes that it does not have the same issue. SLF4J is additionally packaged due to the same linkage error, though it seems to be pulling in an older version from somewhere else. We also need to bump the Kotlin version, since there is a bug where Kotlin compiler runs out of memory for some reason if we exclude Gson from the distribution bundle.
1 parent 9dad6c9 commit 9109943

File tree

22 files changed

+42
-31
lines changed

22 files changed

+42
-31
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix LinkageError while attempting to do Amazon Q inline suggestions in certain environments"
4+
}

buildSrc/src/main/kotlin/software/aws/toolkits/gradle/changelog/ChangeLog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum class ChangeType(val sectionTitle: String) {
3939

4040
class Serializer : StdSerializer<ChangeType>(ChangeType::class.java) {
4141
override fun serialize(value: ChangeType, gen: JsonGenerator?, provider: SerializerProvider?) {
42-
gen?.writeString(value.name.toLowerCase())
42+
gen?.writeString(value.name.lowercase())
4343
}
4444
}
4545
}

buildSrc/src/main/kotlin/software/aws/toolkits/gradle/changelog/tasks/NewChange.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ open class NewChange : ChangeLogTask() {
6565
)
6666
}
6767

68-
private fun newFile(changeType: ChangeType) = nextReleaseDirectory.file("${changeType.name.toLowerCase()}-${UUID.randomUUID()}.json").get().asFile.apply {
68+
private fun newFile(changeType: ChangeType) = nextReleaseDirectory.file("${changeType.name.lowercase()}-${UUID.randomUUID()}.json").get().asFile.apply {
6969
parentFile?.mkdirs()
7070
createNewFile()
7171
}

buildSrc/src/main/kotlin/toolkit-intellij-subplugin.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ configurations {
4848

4949
// Exclude dependencies that ship with iDE
5050
exclude(group = "org.slf4j")
51-
// we want kotlinx-coroutines-debug and kotlinx-coroutines-test
52-
exclude(group = "org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
53-
exclude(group = "org.jetbrains.kotlinx", "kotlinx-coroutines-core")
51+
if (!name.startsWith("kotlinCompiler") && !name.startsWith("generateModels") && !name.startsWith("rdGen")) {
52+
// we want kotlinx-coroutines-debug and kotlinx-coroutines-test
53+
exclude(group = "org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
54+
exclude(group = "org.jetbrains.kotlinx", "kotlinx-coroutines-core")
55+
}
5456

5557
resolutionStrategy.eachDependency {
5658
if (requested.group == "org.jetbrains.kotlinx" && requested.name.startsWith("kotlinx-coroutines")) {

buildSrc/src/main/kotlin/toolkit-publishing-conventions.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ configurations {
5454

5555
// Make sure we exclude stuff we either A) ships with IDE, B) we don't use to cut down on size
5656
runtimeClasspath {
57-
exclude(group = "org.slf4j")
57+
exclude(group = "com.google.code.gson")
58+
exclude(group = "org.slf4j", module = "slf4j-jdk14")
5859
exclude(group = "org.jetbrains.kotlin")
5960
exclude(group = "org.jetbrains.kotlinx")
6061
}

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ junit4 = "4.13.2"
1919
junit5 = "5.11.0"
2020
# https://plugins.jetbrains.com/docs/intellij/kotlin.html#adding-kotlin-support
2121
# https://kotlinlang.org/docs/releases.html#release-details
22-
kotlin = "2.0.0"
22+
kotlin = "2.1.20"
2323
# set in <root>/settings.gradle.kts
2424
kotlinCoroutines = "1.8.0"
25+
lsp4j = "0.24.0"
2526
mockito = "5.12.0"
2627
mockitoKotlin = "5.4.0"
2728
mockk = "1.13.17"
@@ -105,6 +106,7 @@ kotlin-coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-tes
105106
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
106107
kotlin-stdLibJdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
107108
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
109+
lsp4j = { module = "org.eclipse.lsp4j:org.eclipse.lsp4j", version.ref = "lsp4j" }
108110
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }
109111
mockito-junit-jupiter = { module = "org.mockito:mockito-junit-jupiter", version.ref = "mockito" }
110112
mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" }

plugins/amazonq/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation(project(":plugin-amazonq:codewhisperer"))
3737
implementation(project(":plugin-amazonq:mynah-ui"))
3838
implementation(project(":plugin-amazonq:shared"))
39+
implementation(libs.lsp4j)
3940

4041
testImplementation(project(":plugin-core"))
4142
}

plugins/amazonq/codewhisperer/jetbrains-community/tstFixtures/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererTestUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ object CodeWhispererTestUtil {
172172
const val leftContext_success_Iac = "# Create an S3 Bucket named CodeWhisperer in CloudFormation"
173173
const val leftContext_failure_Iac = "Create an S3 Bucket named CodeWhisperer"
174174

175-
internal fun pythonResponseWithToken(token: String): GenerateCompletionsResponse =
175+
fun pythonResponseWithToken(token: String): GenerateCompletionsResponse =
176176
pythonResponse.toBuilder().nextToken(token).build()
177177

178-
internal fun generateMockCompletionDetail(content: String): Completion {
178+
fun generateMockCompletionDetail(content: String): Completion {
179179
val referenceInfo = getReferenceInfo()
180180
return Completion.builder().content(content)
181181
.references(
@@ -184,9 +184,9 @@ object CodeWhispererTestUtil {
184184
.build()
185185
}
186186

187-
internal fun getReferenceInfo() = testReferenceInfoPair[Random.nextInt(testReferenceInfoPair.size)]
187+
fun getReferenceInfo() = testReferenceInfoPair[Random.nextInt(testReferenceInfoPair.size)]
188188

189-
internal fun generateMockCompletionDetail(
189+
fun generateMockCompletionDetail(
190190
content: String,
191191
licenseName: String,
192192
repository: String,

plugins/amazonq/codewhisperer/jetbrains-community/tstFixtures/software/aws/toolkits/jetbrains/services/codewhisperer/importadder/CodeWhispererImportAdderTestBase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlin.test.fail
1818
open class CodeWhispererImportAdderTestBase(
1919
val importAdder: CodeWhispererImportAdder,
2020
@Rule @JvmField val projectRule: CodeInsightTestFixtureRule,
21-
internal val fileExtension: String,
21+
val fileExtension: String,
2222
) {
2323

2424
fun <T> testCreateNewImportPsiElementReturnValueForStatements(

plugins/core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
implementation(project(":plugin-core:resources"))
1616
implementation(project(":plugin-core:sdk-codegen"))
1717
implementation(project(":plugin-core:webview"))
18+
implementation(libs.slf4j.api)
1819
}
1920

2021
tasks.check {

0 commit comments

Comments
 (0)