Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -372,35 +372,35 @@
}

val node = if (SystemInfo.isWindows) "node.exe" else "node"
val cmd = GeneralCommandLine(
artifact.resolve(node).toString(),
LspSettings.getInstance().getArtifactPath() ?: artifact.resolve("aws-lsp-codewhisperer.js").toString(),
"--stdio",
"--set-credentials-encryption-key",
).withEnvironment(
buildMap {
put("NODE_EXTRA_CA_CERTS", extraCaCerts.toAbsolutePath().toString())

val proxy = JdkProxyProvider.getInstance().proxySelector.select(qUri)
// log if only socks proxy available
.firstOrNull { it.type() == Proxy.Type.HTTP }

if (proxy != null) {
val address = proxy.address()
if (address is java.net.InetSocketAddress) {
put(
"HTTPS_PROXY",
URIBuilder("http://${address.hostName}:${address.port}").apply {
val login = HttpConfigurable.getInstance().proxyLogin
if (login != null) {
setUserInfo(login, HttpConfigurable.getInstance().plainProxyPassword)
}
}.build().toASCIIString()
)
val cmd = NodeExePatcher.patch(artifact.resolve(node))
.withParameters(

Check warning on line 376 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L375-L376

Added lines #L375 - L376 were not covered by tests
LspSettings.getInstance().getArtifactPath() ?: artifact.resolve("aws-lsp-codewhisperer.js").toString(),
"--stdio",
"--set-credentials-encryption-key",
).withEnvironment(
buildMap {
put("NODE_EXTRA_CA_CERTS", extraCaCerts.toAbsolutePath().toString())

Check warning on line 382 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L378-L382

Added lines #L378 - L382 were not covered by tests

val proxy = JdkProxyProvider.getInstance().proxySelector.select(qUri)

Check warning on line 384 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L384

Added line #L384 was not covered by tests
// log if only socks proxy available
.firstOrNull { it.type() == Proxy.Type.HTTP }

if (proxy != null) {
val address = proxy.address()

Check warning on line 389 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L389

Added line #L389 was not covered by tests
if (address is java.net.InetSocketAddress) {
put(
"HTTPS_PROXY",
URIBuilder("http://${address.hostName}:${address.port}").apply {
val login = HttpConfigurable.getInstance().proxyLogin

Check warning on line 394 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L391-L394

Added lines #L391 - L394 were not covered by tests
if (login != null) {
setUserInfo(login, HttpConfigurable.getInstance().plainProxyPassword)

Check warning on line 396 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L396

Added line #L396 was not covered by tests
}
}.build().toASCIIString()

Check warning on line 398 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L398

Added line #L398 was not covered by tests
)
}
}
}
}
)
)
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)

launcherHandler = KillableColoredProcessHandler.Silent(cmd)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq.lsp

import com.intellij.execution.configurations.GeneralCommandLine
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import java.nio.file.Path

/**
* Hacky nonsense to support old glibc platforms like AL2
* @see "https://github.com/microsoft/vscode/issues/231623"
* @see "https://github.com/aws/aws-toolkit-vscode/commit/6081f890bdbb91fcd8b60c4cc0abb65b15d4a38d"
*/
object NodeExePatcher {
const val GLIBC_LINKER_VAR = "VSCODE_SERVER_CUSTOM_GLIBC_LINKER"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these env vars always exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the patch is available then yes

const val GLIBC_PATH_VAR = "VSCODE_SERVER_CUSTOM_GLIBC_PATH"

fun patch(node: Path): GeneralCommandLine {
val linker = System.getenv(GLIBC_LINKER_VAR)
val glibc = System.getenv(GLIBC_PATH_VAR)
val nodePath = node.toAbsolutePath().toString()

Check warning on line 23 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt#L21-L23

Added lines #L21 - L23 were not covered by tests

return if (!linker.isNullOrEmpty() && !glibc.isNullOrEmpty()) {
GeneralCommandLine(linker)
.withParameters("--library-path", glibc, nodePath)
.also {
getLogger<NodeExePatcher>().info { "Using glibc patch: $it" }
}

Check warning on line 30 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt#L26-L30

Added lines #L26 - L30 were not covered by tests
} else {
GeneralCommandLine(nodePath)

Check warning on line 32 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/NodeExePatcher.kt#L32

Added line #L32 was not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq.lsp

import com.intellij.execution.configurations.GeneralCommandLine
import org.assertj.core.api.Assertions.assertThat
import org.junit.Rule
import org.junit.Test
import software.aws.toolkits.core.rules.EnvironmentVariableHelper
import kotlin.io.path.Path

class NodeExePatcherTest {
@get:Rule
val envVarHelper = EnvironmentVariableHelper()

private val pathToNode = Path("/path/to/node").toAbsolutePath().toString()

@Test
fun `patches if path available`() {
envVarHelper[NodeExePatcher.GLIBC_LINKER_VAR] = "/opt/vsc-sysroot/lib/ld-linux-x86-64.so.2"
envVarHelper[NodeExePatcher.GLIBC_PATH_VAR] = "/opt/vsc-sysroot/lib/"

assertThat(NodeExePatcher.patch(Path("/path/to/node")))
.usingComparator(Comparator.comparing { it.commandLineString })
.isEqualTo(GeneralCommandLine("/opt/vsc-sysroot/lib/ld-linux-x86-64.so.2", "--library-path", "/opt/vsc-sysroot/lib/", pathToNode))
}

@Test
fun `noop if no patch available`() {
assertThat(NodeExePatcher.patch(Path("/path/to/node")))
.usingComparator(Comparator.comparing { it.commandLineString })
.isEqualTo(GeneralCommandLine(pathToNode))
}
}
Loading