Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c4aa8cb
Added Manifest Fetcher
LokeshDogga13 Feb 18, 2025
d1ca7d1
Addressing code review comments
LokeshDogga13 Feb 18, 2025
600f91a
Added unit test cases
LokeshDogga13 Feb 18, 2025
cad10ef
Fixing lint issues
LokeshDogga13 Feb 18, 2025
2607eec
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 19, 2025
b0e9648
Addressing code review comments
LokeshDogga13 Feb 19, 2025
973b710
Addressing code review comments
LokeshDogga13 Feb 19, 2025
2641472
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 19, 2025
fef3b06
Fixing lint issues
LokeshDogga13 Feb 19, 2025
539cb7e
Merge remote-tracking branch 'origin/lodogga/initialChanges' into lod…
LokeshDogga13 Feb 19, 2025
563ca08
Addressing code review comments
LokeshDogga13 Feb 19, 2025
8f44478
Fixing detektMain lint issues
LokeshDogga13 Feb 19, 2025
30f8dc6
Added unit test cases
LokeshDogga13 Feb 21, 2025
eef3e59
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 21, 2025
bc25fb9
Updating code according to spec.
LokeshDogga13 Feb 24, 2025
7ac76b0
detekt
LokeshDogga13 Feb 24, 2025
a28dca7
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 24, 2025
20e7451
Fixing typo
LokeshDogga13 Feb 24, 2025
a970509
Artifact changes
LokeshDogga13 Feb 25, 2025
44f5c7b
Fixing validation function
LokeshDogga13 Feb 26, 2025
60c4b1c
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 26, 2025
65f6f68
Addressing code review comments
LokeshDogga13 Feb 26, 2025
224289d
Merge branch 'feature/q-lsp' into lodogga/initialChanges
LokeshDogga13 Feb 26, 2025
3e1bc1e
Fixing Detekt
LokeshDogga13 Feb 26, 2025
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
@@ -0,0 +1,187 @@
// 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.artifacts

import com.intellij.util.io.createDirectories
import com.intellij.util.text.SemVer
import software.aws.toolkits.core.utils.deleteIfExists
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.exists
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.core.saveFileFromUrl
import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.ManifestManager
import java.nio.file.Path
import java.util.concurrent.atomic.AtomicInteger

class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH, private val maxDownloadAttempts: Int = MAX_DOWNLOAD_ATTEMPTS) {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L19

Added line #L19 was not covered by tests

companion object {
private val DEFAULT_ARTIFACT_PATH = getToolkitsCommonCacheRoot().resolve("aws").resolve("toolkits").resolve("language-servers")
private val logger = getLogger<ArtifactHelper>()

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L22-L23

Added lines #L22 - L23 were not covered by tests
private const val MAX_DOWNLOAD_ATTEMPTS = 3
}
private val currentAttempt = AtomicInteger(0)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L26 was not covered by tests

fun removeDelistedVersions(delistedVersions: List<ManifestManager.Version>) {
val localFolders = getSubFolders(lspArtifactsPath)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L29

Added line #L29 was not covered by tests

delistedVersions.forEach { delistedVersion ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L31

Added line #L31 was not covered by tests
val versionToDelete = delistedVersion.serverVersion ?: return@forEach

localFolders
.filter { folder -> folder.fileName.toString() == versionToDelete }
.forEach { folder ->
try {
folder.toFile().deleteRecursively()
logger.info { "Successfully deleted deListed version: ${folder.fileName}" }
} catch (e: Exception) {
logger.error(e) { "Failed to delete deListed version ${folder.fileName}: ${e.message}" }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L34-L41

Added lines #L34 - L41 were not covered by tests
}
}
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L43-L45

Added lines #L43 - L45 were not covered by tests

fun deleteOlderLspArtifacts(manifestVersionRanges: ArtifactManager.SupportedManifestVersionRange) {
val localFolders = getSubFolders(lspArtifactsPath)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L48

Added line #L48 was not covered by tests

val validVersions = localFolders
.mapNotNull { localFolder ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L50-L51

Added lines #L50 - L51 were not covered by tests
SemVer.parseFromText(localFolder.fileName.toString())?.let { semVer ->
if (semVer in manifestVersionRanges.startVersion..manifestVersionRanges.endVersion) {
localFolder to semVer

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L54

Added line #L54 was not covered by tests
} else {
null
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L56-L58

Added lines #L56 - L58 were not covered by tests
}
.sortedByDescending { (_, semVer) -> semVer }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L60

Added line #L60 was not covered by tests

// Keep the latest 2 versions, delete others
validVersions.drop(2).forEach { (folder, _) ->
try {
folder.toFile().deleteRecursively()
logger.info { "Deleted older LSP artifact: ${folder.fileName}" }
} catch (e: Exception) {
logger.error(e) { "Failed to delete older LSP artifact: ${folder.fileName}" }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L63-L68

Added lines #L63 - L68 were not covered by tests
}
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L70-L71

Added lines #L70 - L71 were not covered by tests

fun getExistingLspArtifacts(versions: List<ManifestManager.Version>, target: ManifestManager.VersionTarget?): Boolean {
if (versions.isEmpty() || target?.contents == null) return false

val localLSPPath = lspArtifactsPath.resolve(versions.first().serverVersion.toString())

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L76

Added line #L76 was not covered by tests
if (!localLSPPath.exists()) return false

val hasInvalidFiles = target.contents.any { content ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L79

Added line #L79 was not covered by tests
content.filename?.let { filename ->
val filePath = localLSPPath.resolve(filename)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L81

Added line #L81 was not covered by tests
!filePath.exists() || !validateFileHash(filePath, content.hashes?.firstOrNull())
} ?: false

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L83

Added line #L83 was not covered by tests
}

if (hasInvalidFiles) {
try {
localLSPPath.toFile().deleteRecursively()
logger.info { "Deleted mismatched LSP artifacts at: $localLSPPath" }
} catch (e: Exception) {
logger.error(e) { "Failed to delete mismatched LSP artifacts at: $localLSPPath" }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L87-L91

Added lines #L87 - L91 were not covered by tests
}
}
return !hasInvalidFiles
}

fun tryDownloadLspArtifacts(versions: List<ManifestManager.Version>, target: ManifestManager.VersionTarget?) {
val temporaryDownloadPath = lspArtifactsPath.resolve("temp")
val downloadPath = lspArtifactsPath.resolve(versions.first().serverVersion.toString())

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L98-L99

Added lines #L98 - L99 were not covered by tests

while (currentAttempt.get() < maxDownloadAttempts) {
currentAttempt.incrementAndGet()
logger.info { "Attempt ${currentAttempt.get()} of $maxDownloadAttempts to download LSP artifacts" }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L102-L103

Added lines #L102 - L103 were not covered by tests

try {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L105

Added line #L105 was not covered by tests
if (downloadLspArtifacts(temporaryDownloadPath, target)) {
moveFilesFromSourceToDestination(temporaryDownloadPath, downloadPath)
logger.info { "Successfully downloaded and moved LSP artifacts to $downloadPath" }
return

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L107-L109

Added lines #L107 - L109 were not covered by tests
}
} catch (e: Exception) {
logger.error(e) { "Failed to download/move LSP artifacts on attempt ${currentAttempt.get()}" }
temporaryDownloadPath.toFile().deleteRecursively()

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L111-L113

Added lines #L111 - L113 were not covered by tests

if (currentAttempt.get() >= maxDownloadAttempts) {
throw LspException("Failed to download LSP artifacts after $maxDownloadAttempts attempts", LspException.ErrorCode.DOWNLOAD_FAILED)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L116

Added line #L116 was not covered by tests
}
}
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L120

Added line #L120 was not covered by tests

private fun downloadLspArtifacts(downloadPath: Path, target: ManifestManager.VersionTarget?): Boolean {
if (target == null || target.contents.isNullOrEmpty()) {
logger.warn { "No target contents available for download" }
return false

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L124-L125

Added lines #L124 - L125 were not covered by tests
}
try {
downloadPath.createDirectories()
target.contents.forEach { content ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L127-L129

Added lines #L127 - L129 were not covered by tests
if (content.url == null || content.filename == null) {
logger.warn { "Missing URL or filename in content" }
return@forEach

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L131-L132

Added lines #L131 - L132 were not covered by tests
}
val filePath = downloadPath.resolve(content.filename)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L134

Added line #L134 was not covered by tests
val contentHash = content.hashes?.firstOrNull() ?: run {
logger.warn { "No hash available for ${content.filename}" }
return@forEach

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L136-L137

Added lines #L136 - L137 were not covered by tests
}
downloadAndValidateFile(content.url, filePath, contentHash)
}
validateDownloadedFiles(downloadPath, target.contents)
} catch (e: Exception) {
logger.error(e) { "Failed to download LSP artifacts: ${e.message}" }
downloadPath.toFile().deleteRecursively()
return false

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L139-L145

Added lines #L139 - L145 were not covered by tests
}
return true

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L147

Added line #L147 was not covered by tests
}

private fun downloadAndValidateFile(url: String, filePath: Path, expectedHash: String) {
try {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L151

Added line #L151 was not covered by tests
if (!filePath.exists()) {
logger.info { "Downloading file: ${filePath.fileName}" }
saveFileFromUrl(url, filePath)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L153-L154

Added lines #L153 - L154 were not covered by tests
}
if (!validateFileHash(filePath, expectedHash)) {
logger.warn { "Hash mismatch for ${filePath.fileName}, re-downloading" }
filePath.deleteIfExists()
saveFileFromUrl(url, filePath)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L157-L159

Added lines #L157 - L159 were not covered by tests
if (!validateFileHash(filePath, expectedHash)) {
throw LspException("Hash mismatch after re-download for ${filePath.fileName}", LspException.ErrorCode.HASH_MISMATCH)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L161

Added line #L161 was not covered by tests
}
}
} catch (e: Exception) {
throw IllegalStateException("Failed to download/validate file: ${filePath.fileName}", e)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L164-L165

Added lines #L164 - L165 were not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L167

Added line #L167 was not covered by tests

private fun validateFileHash(filePath: Path, expectedHash: String?): Boolean {
if (expectedHash == null) return false
val contentHash = generateSHA384Hash(filePath)
return "sha384:$contentHash" == expectedHash

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L171-L172

Added lines #L171 - L172 were not covered by tests
}

private fun validateDownloadedFiles(downloadPath: Path, contents: List<ManifestManager.TargetContent>) {
val missingFiles = contents
.mapNotNull { it.filename }
.filter { filename ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L176-L178

Added lines #L176 - L178 were not covered by tests
!downloadPath.resolve(filename).exists()
}
if (missingFiles.isNotEmpty()) {
val errorMessage = "Missing required files: ${missingFiles.joinToString(", ")}"
logger.error { errorMessage }
throw LspException(errorMessage, LspException.ErrorCode.DOWNLOAD_FAILED)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L182-L184

Added lines #L182 - L184 were not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactHelper.kt#L186

Added line #L186 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// 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.artifacts

import com.intellij.util.text.SemVer
import org.assertj.core.util.VisibleForTesting
import software.aws.toolkits.core.utils.error
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.ManifestManager

class ArtifactManager {

data class SupportedManifestVersionRange(
val startVersion: SemVer,
val endVersion: SemVer,

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L15-L17

Added lines #L15 - L17 were not covered by tests
)
data class LSPVersions(
val deListedVersions: List<ManifestManager.Version>,
val inRangeVersions: List<ManifestManager.Version>,

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L19-L21

Added lines #L19 - L21 were not covered by tests
)

private val manifestFetcher: ManifestFetcher
private val artifactHelper: ArtifactHelper
private val manifestVersionRanges: SupportedManifestVersionRange

// Primary constructor with config
constructor(
manifestFetcher: ManifestFetcher = ManifestFetcher(),
artifactFetcher: ArtifactHelper = ArtifactHelper(),

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L29-L31

Added lines #L29 - L31 were not covered by tests
manifestRange: SupportedManifestVersionRange?,
) {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L33

Added line #L33 was not covered by tests
manifestVersionRanges = manifestRange ?: DEFAULT_VERSION_RANGE
this.manifestFetcher = manifestFetcher
this.artifactHelper = artifactFetcher
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L35-L37

Added lines #L35 - L37 were not covered by tests

// Secondary constructor with no parameters
constructor() : this(ManifestFetcher(), ArtifactHelper(), null)

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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Constructor is never used

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L40

Added line #L40 was not covered by tests

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Constructor is never used

companion object {
private val DEFAULT_VERSION_RANGE = SupportedManifestVersionRange(
startVersion = SemVer("3.0.0", 3, 0, 0),
endVersion = SemVer("4.0.0", 4, 0, 0)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L43-L45

Added lines #L43 - L45 were not covered by tests
)
private val logger = getLogger<ArtifactManager>()

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L47

Added line #L47 was not covered by tests
}

fun fetchArtifact() {

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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "fetchArtifact" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Function "fetchArtifact" is never used
val manifest = manifestFetcher.fetch() ?: throw LspException(
"Language Support is not available, as manifest is missing.",
LspException.ErrorCode.MANIFEST_FETCH_FAILED

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L52-L53

Added lines #L52 - L53 were not covered by tests
)
val lspVersions = getLSPVersionsFromManifestWithSpecifiedRange(manifest)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L55

Added line #L55 was not covered by tests

this.artifactHelper.removeDelistedVersions(lspVersions.deListedVersions)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L57

Added line #L57 was not covered by tests

if (lspVersions.inRangeVersions.isEmpty()) {
// No versions are found which are in the given range.
throw LspException("Language server versions not found in manifest.", LspException.ErrorCode.NO_COMPATIBLE_LSP_VERSION)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L61

Added line #L61 was not covered by tests
}

// If there is an LSP Manifest with the same version
val target = getTargetFromLspManifest(lspVersions.inRangeVersions)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L65

Added line #L65 was not covered by tests

// Get Local LSP files and check if we can re-use existing LSP Artifacts
if (!this.artifactHelper.getExistingLspArtifacts(lspVersions.inRangeVersions, target)) {
this.artifactHelper.tryDownloadLspArtifacts(lspVersions.inRangeVersions, target)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L69

Added line #L69 was not covered by tests
}

this.artifactHelper.deleteOlderLspArtifacts(manifestVersionRanges)
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L72-L73

Added lines #L72 - L73 were not covered by tests

@VisibleForTesting
internal fun getLSPVersionsFromManifestWithSpecifiedRange(manifest: ManifestManager.Manifest): LSPVersions {
if (manifest.versions.isNullOrEmpty()) return LSPVersions(emptyList(), emptyList())

val (deListed, inRange) = manifest.versions.mapNotNull { version ->

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L79

Added line #L79 was not covered by tests
version.serverVersion?.let { serverVersion ->
SemVer.parseFromText(serverVersion)?.let { semVer ->
when {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L82

Added line #L82 was not covered by tests
version.isDelisted != false -> Pair(version, true) // Is deListed
semVer in manifestVersionRanges.startVersion..manifestVersionRanges.endVersion -> Pair(version, false) // Is in range
else -> null
}
}
}
}.partition { it.second }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L85-L89

Added lines #L85 - L89 were not covered by tests

return LSPVersions(
deListedVersions = deListed.map { it.first },
inRangeVersions = inRange.map { it.first }.sortedByDescending { (_, semVer) -> semVer }

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L91-L93

Added lines #L91 - L93 were not covered by tests
)
}

private fun getTargetFromLspManifest(versions: List<ManifestManager.Version>): ManifestManager.VersionTarget {
val currentOS = getCurrentOS()
val currentArchitecture = getCurrentArchitecture()

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L98-L99

Added lines #L98 - L99 were not covered by tests

val currentTarget = versions.first().targets?.find { target ->
target.platform == currentOS && target.arch == currentArchitecture
}
if (currentTarget == null) {
logger.error { "Failed to obtain target for $currentOS and $currentArchitecture" }
throw LspException("Target not found in the current Version: ${versions.first().serverVersion}", LspException.ErrorCode.TARGET_NOT_FOUND)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L105-L106

Added lines #L105 - L106 were not covered by tests
}
logger.info { "Target found in the current Version: ${versions.first().serverVersion}" }
return currentTarget

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/ArtifactManager.kt#L108-L109

Added lines #L108 - L109 were not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.artifacts

class LspException(message: String, private val errorCode: ErrorCode, cause: Throwable? = null) : Exception(message, cause) {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspException.kt#L6

Added line #L6 was not covered by tests

enum class ErrorCode {
MANIFEST_FETCH_FAILED,
DOWNLOAD_FAILED,
HASH_MISMATCH,
TARGET_NOT_FOUND,
NO_COMPATIBLE_LSP_VERSION,
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspException.kt#L9-L14

Added lines #L9 - L14 were not covered by tests

override fun toString(): String = buildString {
append("LSP Error [$errorCode]: $message")

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspException.kt#L16-L17

Added lines #L16 - L17 were not covered by tests
cause?.let { append(", Cause: ${it.message}") }
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspException.kt#L19

Added line #L19 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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.artifacts

import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.text.StringUtil
import com.intellij.util.io.DigestUtil
import com.intellij.util.system.CpuArch
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.security.MessageDigest
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries

fun getToolkitsCommonCacheRoot(): Path = when {

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L18

Added line #L18 was not covered by tests
SystemInfo.isWindows -> {
Paths.get(System.getenv("LOCALAPPDATA"))

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L20

Added line #L20 was not covered by tests
}
SystemInfo.isMac -> {
Paths.get(System.getProperty("user.home"), "Library", "Caches")

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L23 was not covered by tests
}
else -> {
Paths.get(System.getProperty("user.home"), ".cache")

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L25-L26

Added lines #L25 - L26 were not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L28

Added line #L28 was not covered by tests

fun getCurrentOS(): String = when {

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L30 was not covered by tests
SystemInfo.isWindows -> "windows"
SystemInfo.isMac -> "darwin"
else -> "linux"
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L33-L34

Added lines #L33 - L34 were not covered by tests

fun getCurrentArchitecture() = when (CpuArch.CURRENT) {
CpuArch.X86_64 -> "x64"
CpuArch.ARM64 -> "arm64"
else -> "unknown"
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L37-L40

Added lines #L37 - L40 were not covered by tests

fun generateMD5Hash(filePath: Path): String {
val messageDigest = DigestUtil.md5()
DigestUtil.updateContentHash(messageDigest, filePath)
return StringUtil.toHexString(messageDigest.digest())

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L43-L45

Added lines #L43 - L45 were not covered by tests
}

fun generateSHA384Hash(filePath: Path): String {
val messageDigest = MessageDigest.getInstance("SHA-384")
DigestUtil.updateContentHash(messageDigest, filePath)
return StringUtil.toHexString(messageDigest.digest())

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L49-L51

Added lines #L49 - L51 were not covered by tests
}

fun getSubFolders(basePath: Path): List<Path> = try {
basePath.listDirectoryEntries()
.filter { it.isDirectory() }
} catch (e: Exception) {
emptyList()
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L54-L59

Added lines #L54 - L59 were not covered by tests

fun moveFilesFromSourceToDestination(sourceDir: Path, targetDir: Path) {
try {
Files.createDirectories(targetDir.parent)
Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING)
} catch (e: Exception) {
throw IllegalStateException("Failed to move files from $sourceDir to $targetDir", e)

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L62-L66

Added lines #L62 - L66 were not covered by tests
}
}

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

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/artifacts/LspUtils.kt#L68

Added line #L68 was not covered by tests
Loading
Loading