Skip to content

Commit 3e1bc1e

Browse files
committed
Fixing Detekt
1 parent 224289d commit 3e1bc1e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts
55

6-
import com.intellij.openapi.actionSystem.AnAction
7-
import com.intellij.openapi.actionSystem.AnActionEvent
86
import com.intellij.util.io.createDirectories
97
import com.intellij.util.text.SemVer
108
import software.aws.toolkits.core.utils.deleteIfExists
@@ -18,7 +16,7 @@ import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.Manifes
1816
import java.nio.file.Path
1917
import java.util.concurrent.atomic.AtomicInteger
2018

21-
class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH) {
19+
class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH, private val maxDownloadAttempts: Int = MAX_DOWNLOAD_ATTEMPTS) {
2220

2321
companion object {
2422
private val DEFAULT_ARTIFACT_PATH = getToolkitsCommonCacheRoot().resolve("aws").resolve("toolkits").resolve("language-servers")
@@ -54,7 +52,9 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH)
5452
SemVer.parseFromText(localFolder.fileName.toString())?.let { semVer ->
5553
if (semVer in manifestVersionRanges.startVersion..manifestVersionRanges.endVersion) {
5654
localFolder to semVer
57-
} else null
55+
} else {
56+
null
57+
}
5858
}
5959
}
6060
.sortedByDescending { (_, semVer) -> semVer }
@@ -98,9 +98,9 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH)
9898
val temporaryDownloadPath = lspArtifactsPath.resolve("temp")
9999
val downloadPath = lspArtifactsPath.resolve(versions.first().serverVersion.toString())
100100

101-
while (currentAttempt.get() < MAX_DOWNLOAD_ATTEMPTS) {
101+
while (currentAttempt.get() < maxDownloadAttempts) {
102102
currentAttempt.incrementAndGet()
103-
logger.info { "Attempt ${currentAttempt.get()} of $MAX_DOWNLOAD_ATTEMPTS to download LSP artifacts" }
103+
logger.info { "Attempt ${currentAttempt.get()} of $maxDownloadAttempts to download LSP artifacts" }
104104

105105
try {
106106
if (downloadLspArtifacts(temporaryDownloadPath, target)) {
@@ -112,8 +112,8 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH)
112112
logger.error(e) { "Failed to download/move LSP artifacts on attempt ${currentAttempt.get()}" }
113113
temporaryDownloadPath.toFile().deleteRecursively()
114114

115-
if (currentAttempt.get() >= MAX_DOWNLOAD_ATTEMPTS) {
116-
throw LspException("Failed to download LSP artifacts after $MAX_DOWNLOAD_ATTEMPTS attempts", LspException.ErrorCode.DOWNLOAD_FAILED)
115+
if (currentAttempt.get() >= maxDownloadAttempts) {
116+
throw LspException("Failed to download LSP artifacts after $maxDownloadAttempts attempts", LspException.ErrorCode.DOWNLOAD_FAILED)
117117
}
118118
}
119119
}
@@ -167,7 +167,7 @@ class ArtifactHelper(private val lspArtifactsPath: Path = DEFAULT_ARTIFACT_PATH)
167167
}
168168

169169
private fun validateFileHash(filePath: Path, expectedHash: String?): Boolean {
170-
if(expectedHash == null) return false
170+
if (expectedHash == null) return false
171171
val contentHash = generateSHA384Hash(filePath)
172172
return "sha384:$contentHash" == expectedHash
173173
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.intellij.util.text.SemVer
77
import org.assertj.core.util.VisibleForTesting
88
import software.aws.toolkits.core.utils.error
99
import software.aws.toolkits.core.utils.getLogger
10+
import software.aws.toolkits.core.utils.info
1011
import software.aws.toolkits.jetbrains.services.amazonq.project.manifest.ManifestManager
1112

1213
class ArtifactManager {
@@ -101,11 +102,10 @@ class ArtifactManager {
101102
target.platform == currentOS && target.arch == currentArchitecture
102103
}
103104
if (currentTarget == null) {
104-
logger.error {"Failed to obtain target for $currentOS and $currentArchitecture" }
105+
logger.error { "Failed to obtain target for $currentOS and $currentArchitecture" }
105106
throw LspException("Target not found in the current Version: ${versions.first().serverVersion}", LspException.ErrorCode.TARGET_NOT_FOUND)
106107
}
107-
logger.info("Target found in the current Version: ${versions.first().serverVersion}")
108+
logger.info { "Target found in the current Version: ${versions.first().serverVersion}" }
108109
return currentTarget
109110
}
110-
111111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fun getCurrentOS(): String = when {
3333
else -> "linux"
3434
}
3535

36-
fun getCurrentArchitecture() = when(CpuArch.CURRENT) {
36+
fun getCurrentArchitecture() = when (CpuArch.CURRENT) {
3737
CpuArch.X86_64 -> "x64"
3838
CpuArch.ARM64 -> "arm64"
3939
else -> "unknown"

0 commit comments

Comments
 (0)